/* R-Tech CRM -- admin styles
   Brand: black + red (#ff0044) per r-tech.com.my.
   Base + components ported from the R-Tech Time Card System; CRM additions
   (status badges, Kanban board, toolbar, quote print) below. */

:root {
    --rt-red: #ff0044;
    --rt-red-hover: #e6003c;
    --rt-red-active: #cc0036;
    --rt-red-soft: rgba(255, 0, 68, 0.12);
    --rt-black: #000000;
    --rt-near-black: #111111;
    --rt-surface-dark: #222222;
    --rt-text: #1f2937;
    --rt-muted: #6b7280;
    --rt-bg: #f7f8fa;
    --rt-border: #e5e7eb;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, system-ui, sans-serif;
    background: var(--rt-bg);
    color: var(--rt-text);
    -webkit-font-smoothing: antialiased;
}
a { color: var(--rt-red); }
a:hover { color: var(--rt-red-hover); }

/* ===== Header ===== */
.admin-header {
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    background: var(--rt-black);
    color: #fff;
    height: 60px;
    border-bottom: 3px solid var(--rt-red);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.2);
}
.brand-link {
    display: inline-flex;
    align-items: baseline;
    gap: 0.35rem;
    text-decoration: none;
    flex-shrink: 0;
    margin-right: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.01em;
    font-size: 1.15rem;
}
.brand-word { color: #fff; }
.brand-accent {
    color: var(--rt-red);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    transform: translateY(-1px);
}
.admin-nav { display: flex; gap: 0.25rem; flex: 1; flex-wrap: wrap; }
.admin-nav a {
    color: rgba(255, 255, 255, 0.7);
    text-decoration: none;
    padding: 0.5rem 0.8rem;
    border-radius: 6px;
    font-size: 0.88rem;
    font-weight: 500;
    transition: background 120ms, color 120ms;
}
.admin-nav a:hover { background: rgba(255, 0, 68, 0.15); color: #fff; }
.admin-nav a.active {
    background: var(--rt-red);
    color: #fff;
}
.admin-user {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    font-size: 0.85rem;
    color: rgba(255, 255, 255, 0.7);
}
.admin-user .who { font-weight: 600; color: rgba(255,255,255,0.9); }
.admin-user > a {
    color: var(--rt-red);
    text-decoration: none;
    font-weight: 500;
}
.admin-user > a:hover { color: #ff5079; }
.lang-switch { display: inline-flex; gap: 0.25rem; }
.lang-switch a {
    color: rgba(255, 255, 255, 0.55);
    text-decoration: none;
    font-size: 0.78rem;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
}
.lang-switch a.on { color: #fff; background: rgba(255,255,255,0.12); font-weight: 700; }

.admin-main { padding: 1.5rem; max-width: 1320px; margin: 0 auto; }
.admin-footer {
    text-align: center;
    padding: 1rem;
    color: var(--rt-muted);
    font-size: 0.8rem;
    border-top: 1px solid var(--rt-border);
    margin-top: 2rem;
    background: #fff;
}

/* ===== Page toolbar (title + actions) ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}
.toolbar h1 { margin: 0; font-size: 1.5rem; color: var(--rt-black); }
.toolbar .spacer { flex: 1; }

/* ===== Cards ===== */
.card {
    background: #fff;
    border-radius: 10px;
    padding: 1.5rem 1.75rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
    margin-bottom: 1rem;
    border-top: 3px solid transparent;
    transition: border-top-color 200ms;
}
.card:hover { border-top-color: var(--rt-red); }
.card h1, .card h2 { margin-top: 0; color: var(--rt-black); }
.placeholder {
    padding: 3rem 2rem;
    text-align: center;
    color: var(--rt-muted);
    border: 2px dashed var(--rt-border);
    border-radius: 10px;
    background: #fff;
}

/* ===== Stat row ===== */
.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat {
    background: #fff;
    border-radius: 8px;
    padding: 1rem 1.25rem;
    border-left: 4px solid #d1d5db;
    display: flex;
    flex-direction: column;
    box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}
.stat .num {
    font-size: 1.85rem;
    font-weight: 800;
    color: var(--rt-black);
    font-variant-numeric: tabular-nums;
    line-height: 1.1;
    letter-spacing: -0.02em;
}
.stat .lbl { color: var(--rt-muted); font-size: 0.85rem; }
.stat.red    { border-left-color: var(--rt-red); }
.stat.green  { border-left-color: #059669; }
.stat.black  { border-left-color: var(--rt-black); }
.stat.amber  { border-left-color: #d97706; }

/* ===== Tables ===== */
.data-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.data-table thead th {
    text-align: left;
    padding: 0.6rem 0.75rem;
    background: var(--rt-black);
    color: #fff;
    border-bottom: 2px solid var(--rt-red);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.data-table tbody td { padding: 0.65rem 0.75rem; border-bottom: 1px solid #f3f4f6; }
.data-table tbody tr:hover { background: rgba(255, 0, 68, 0.04); }
.data-table .num-cell { text-align: right; font-variant-numeric: tabular-nums; }

/* ===== Status badges ===== */
.badge {
    display: inline-block;
    padding: 0.15rem 0.6rem;
    border-radius: 999px;
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: #e5e7eb;
    color: #374151;
}
/* lead / generic */
.badge--new        { background: #dbeafe; color: #1e40af; }
.badge--contacted  { background: #fef3c7; color: #92400e; }
.badge--qualified  { background: #e0e7ff; color: #3730a3; }
.badge--converted  { background: #d1fae5; color: #065f46; }
.badge--lost       { background: #1f1f1f; color: #fff; }
/* company */
.badge--prospect   { background: #fef3c7; color: #92400e; }
.badge--active     { background: #d1fae5; color: #065f46; }
.badge--inactive   { background: #e5e7eb; color: #6b7280; }
/* quotation */
.badge--draft      { background: #e5e7eb; color: #374151; }
.badge--sent       { background: #dbeafe; color: #1e40af; }
.badge--accepted   { background: #d1fae5; color: #065f46; }
.badge--rejected   { background: #fee2e2; color: #991b1b; }
.badge--expired    { background: #1f1f1f; color: #fff; }

.ok { color: #059669; font-weight: 500; }
.warn { color: var(--rt-red); font-weight: 600; }
.muted { color: var(--rt-muted); }
.muted.small { font-size: 0.8rem; }

/* ===== Kanban (pipeline) ===== */
.kanban {
    display: flex;
    gap: 0.85rem;
    overflow-x: auto;
    padding-bottom: 0.75rem;
    -webkit-overflow-scrolling: touch;
}
.kanban-col {
    flex: 0 0 280px;
    background: #eef0f3;
    border-radius: 10px;
    padding: 0.65rem;
    display: flex;
    flex-direction: column;
    min-height: 120px;
}
.kanban-col__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-weight: 700;
    font-size: 0.82rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--rt-near-black);
    padding: 0.25rem 0.4rem 0.55rem;
    border-bottom: 2px solid var(--rt-red);
    margin-bottom: 0.5rem;
}
.kanban-col__head .count {
    background: var(--rt-black); color: #fff;
    border-radius: 999px; padding: 0.05rem 0.5rem; font-size: 0.72rem;
}
.kanban-col.is-won  .kanban-col__head { border-bottom-color: #059669; }
.kanban-col.is-lost .kanban-col__head { border-bottom-color: #6b7280; }
.kanban-col__body { display: flex; flex-direction: column; gap: 0.5rem; flex: 1; min-height: 40px; }
.deal-card {
    background: #fff;
    border-radius: 8px;
    padding: 0.65rem 0.75rem;
    box-shadow: 0 1px 2px rgba(0,0,0,0.08);
    border-left: 3px solid var(--rt-red);
    cursor: grab;
}
.deal-card:active { cursor: grabbing; }
.deal-card.dragging { opacity: 0.5; }
.deal-card__title { font-weight: 600; font-size: 0.9rem; color: var(--rt-black); }
.deal-card__meta { font-size: 0.78rem; color: var(--rt-muted); margin-top: 0.2rem; }
.deal-card__amount { font-weight: 700; font-variant-numeric: tabular-nums; }
.kanban-col__body.drop-hover { outline: 2px dashed var(--rt-red); outline-offset: -4px; border-radius: 8px; }

/* ===== Forms ===== */
.form-row { margin-bottom: 1rem; }
.form-row label { display: block; margin-bottom: 0.4rem; font-size: 0.88rem; font-weight: 600; color: #374151; }
.req { color: var(--rt-red); }
.form-row input, .form-row select, .form-row textarea {
    width: 100%;
    padding: 0.6rem 0.75rem;
    border: 1px solid #d1d5db;
    border-radius: 6px;
    font-size: 0.95rem;
    background: #fff;
    color: var(--rt-text);
    font-family: inherit;
    transition: border-color 120ms, box-shadow 120ms;
}
.form-row textarea { min-height: 90px; resize: vertical; }
.form-row input:focus, .form-row select:focus, .form-row textarea:focus {
    outline: none; border-color: var(--rt-red); box-shadow: 0 0 0 3px rgba(255, 0, 68, 0.15);
}
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
}

/* ===== Buttons ===== */
.btn {
    padding: 0.55rem 1.1rem;
    border-radius: 8px;
    border: 0;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    transition: background 120ms, transform 80ms;
}
.btn-primary {
    background: var(--rt-red); color: #fff;
    box-shadow: 0 4px 12px rgba(255, 0, 68, 0.25);
}
.btn-primary:hover:not(:disabled) { background: var(--rt-red-hover); color: #fff; }
.btn-primary:active:not(:disabled) { background: var(--rt-red-active); transform: translateY(1px); }
.btn-primary:disabled { background: #9ca3af; cursor: wait; box-shadow: none; }
.btn-ghost { background: #fff; color: var(--rt-text); border: 1px solid var(--rt-border); }
.btn-ghost:hover { border-color: var(--rt-red); color: var(--rt-red); }
.btn-block { width: 100%; justify-content: center; padding: 0.8rem; font-weight: 700; }

.btn-mini {
    padding: 0.32rem 0.7rem; font-size: 0.82rem; background: var(--rt-red);
    color: #fff; border: 0; border-radius: 5px; cursor: pointer; font-weight: 600;
    text-decoration: none;
}
.btn-mini:hover { background: var(--rt-red-hover); color: #fff; }
.btn-mini.ghost { background: #fff; color: var(--rt-red); border: 1px solid var(--rt-border); }

.link-action {
    background: none; border: 0; padding: 0.25rem 0.5rem; color: var(--rt-red);
    cursor: pointer; font-size: 0.85rem; font-weight: 500;
}
.link-action:hover { text-decoration: underline; color: var(--rt-red-hover); }

/* ===== Alerts ===== */
.alert { padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1rem; font-size: 0.9rem; border-left: 4px solid transparent; }
.alert-error { background: var(--rt-red-soft); color: #7a0021; border-left-color: var(--rt-red); }
.alert-info { background: #f3f4f6; color: #1f2937; border-left-color: var(--rt-black); }
.alert-success { background: #d1fae5; color: #065f46; border-left-color: #059669; }

/* ===== Search / filter bar ===== */
.search-row { display: flex; gap: 0.75rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.search-input, .filter-select {
    padding: 0.55rem 0.9rem; border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.95rem; background: #fff;
}
.search-input { flex: 1; max-width: 340px; }
.search-input:focus, .filter-select:focus { outline: none; border-color: var(--rt-red); box-shadow: 0 0 0 3px rgba(255, 0, 68, 0.15); }

/* ===== Login page ===== */
.login-page {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background:
        radial-gradient(ellipse at top right, rgba(255, 0, 68, 0.4) 0%, transparent 55%),
        radial-gradient(ellipse at bottom left, rgba(255, 0, 68, 0.15) 0%, transparent 50%),
        linear-gradient(180deg, #000000 0%, #0a0005 60%, #1a0010 100%);
    padding: 2rem;
}
.login-stack { width: 100%; max-width: 420px; display: flex; flex-direction: column; align-items: center; gap: 1.25rem; }
.login-brand { color: #fff; font-weight: 800; font-size: 2rem; letter-spacing: -0.02em; }
.login-brand span { color: var(--rt-red); }
.login-card {
    background: #fff; padding: 2rem; border-radius: 14px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.4); width: 100%; max-width: 420px;
    border-top: 4px solid var(--rt-red);
}
.login-card h1 { margin: 0 0 0.25rem 0; font-size: 1.6rem; font-weight: 800; color: var(--rt-black); letter-spacing: -0.01em; }
.login-card .subtitle { color: var(--rt-muted); margin: 0 0 1.5rem 0; font-size: 0.95rem; }

/* ===== Detail layout (record + timeline) ===== */
.split { display: grid; grid-template-columns: 1.4fr 1fr; gap: 1rem; align-items: start; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 0.6rem 0 0.6rem 1rem; border-left: 2px solid var(--rt-border); position: relative; }
.timeline li::before { content: ''; position: absolute; left: -5px; top: 0.85rem; width: 8px; height: 8px; border-radius: 50%; background: var(--rt-red); }
.timeline .ts { font-size: 0.75rem; color: var(--rt-muted); }

/* ===== Hamburger / mobile drawer ===== */
.nav-toggle { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.hamburger-btn {
    display: none; background: none; border: 0; color: rgba(255, 255, 255, 0.85);
    cursor: pointer; padding: 0.5rem; border-radius: 8px; margin-left: auto;
    align-items: center; justify-content: center;
}
.hamburger-btn:hover { background: rgba(255, 255, 255, 0.1); color: #fff; }
.hamburger-icon { display: block; }
.hamburger-icon--close { display: none; }
.admin-drawer { display: contents; }
.table-wrap { width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }

@media (max-width: 980px) {
    .admin-header { position: relative; padding: 0 0.85rem; height: 56px; gap: 0.5rem; }
    .hamburger-btn { display: inline-flex; }
    .nav-toggle:checked ~ .hamburger-btn .hamburger-icon--open  { display: none; }
    .nav-toggle:checked ~ .hamburger-btn .hamburger-icon--close { display: block; }
    .admin-drawer {
        display: none; position: absolute; top: 100%; left: 0; right: 0;
        flex-direction: column; background: var(--rt-black); padding: 0.6rem;
        border-bottom: 3px solid var(--rt-red); box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
        max-height: calc(100vh - 56px); overflow-y: auto; z-index: 50;
    }
    .nav-toggle:checked ~ .admin-drawer { display: flex; }
    .admin-nav { flex: 0 0 auto; flex-direction: column; gap: 0.15rem; }
    .admin-nav a { padding: 0.85rem 1rem; font-size: 0.95rem; border-radius: 8px; }
    .admin-user {
        flex-direction: row; align-items: center; justify-content: space-between;
        margin-top: 0.85rem; padding-top: 0.85rem; border-top: 1px solid rgba(255, 255, 255, 0.12);
    }
    .split { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
    .admin-main { padding: 0.85rem; }
    .card { padding: 1rem 1.1rem; border-radius: 8px; }
    .data-table { font-size: 0.85rem; }
    .data-table thead th, .data-table tbody td { padding: 0.5rem 0.65rem; white-space: nowrap; }
    .form-grid { grid-template-columns: 1fr; }
    .search-input { max-width: 100%; }
}

/* ===== Print (quotation) ===== */
@media print {
    .admin-header, .admin-footer, .toolbar .btn, .no-print { display: none !important; }
    body { background: #fff; }
    .admin-main { max-width: none; padding: 0; }
    .card { box-shadow: none; border: 0; }
}
