/* ===========================================================
   Zoan CRM — Minimal-look design system (preview)
   Exact tokens from the open-source (MIT) Minimal theme
   =========================================================== */
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:opsz,wght@9..40,400;9..40,500;9..40,600;9..40,700&family=Barlow:wght@600;700;800&display=swap');

:root {
    --primary-lighter: #C8FAD6; --primary-light: #5BE49B; --primary-main: #00A76F; --primary-dark: #007867; --primary-darker: #004B50;
    --secondary-lighter: #EFD6FF; --secondary-main: #8E33FF; --secondary-dark: #5119B7;
    --info-lighter: #CAFDF5; --info-main: #00B8D9; --info-dark: #006C9C;
    --success-lighter: #D3FCD2; --success-main: #22C55E; --success-dark: #118D57;
    --warning-lighter: #FFF5CC; --warning-main: #FFAB00; --warning-dark: #B76E00;
    --error-lighter: #FFE9D5; --error-main: #FF5630; --error-dark: #B71D18;

    --grey-100: #F9FAFB; --grey-200: #F4F6F8; --grey-300: #DFE3E8; --grey-400: #C4CDD5;
    --grey-500: #919EAB; --grey-600: #637381; --grey-700: #454F5B; --grey-800: #1C252E; --grey-900: #141A21;

    --text-primary: #1C252E; --text-secondary: #637381; --text-disabled: #919EAB;
    --bg-default: #FFFFFF; --bg-neutral: #F4F6F8;

    --shadow-card: 0 0 2px 0 rgba(145,158,171,0.2), 0 12px 24px -4px rgba(145,158,171,0.12);
    --shadow-z8: 0 8px 16px 0 rgba(145,158,171,0.16);
    --shadow-z16: 0 16px 32px -4px rgba(145,158,171,0.16);
    --shadow-dropdown: 0 0 2px 0 rgba(145,158,171,0.24), -20px 20px 40px -4px rgba(145,158,171,0.24);
    --shadow-primary: 0 8px 16px 0 rgba(0,167,111,0.24);
}

* { font-family: 'DM Sans', sans-serif; -webkit-font-smoothing: antialiased; box-sizing: border-box; }
html { max-width: 100%; overflow-x: hidden; }
body { background: var(--bg-neutral); color: var(--text-primary); margin: 0; max-width: 100%; overflow-x: hidden; }
h1, h2, h3, .font-display { font-family: 'Barlow', 'DM Sans', sans-serif; }

/* Cards */
.zcard { background: #fff; border-radius: 16px; box-shadow: var(--shadow-card); }
.stat-card { border-radius: 16px; padding: 24px; position: relative; overflow: hidden; }

/* Sidebar */
.sb { width: 280px; flex-shrink: 0; background: #fff; border-right: 1px solid var(--grey-200); padding: 24px 16px; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.sb-item { display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 8px; font-size: 14px; color: var(--text-secondary); text-decoration: none; transition: all .15s ease; font-weight: 500; }
.sb-item:hover { background: var(--grey-200); color: var(--text-primary); }
.sb-item.active { background: rgba(0,167,111,0.08); color: var(--primary-dark); font-weight: 600; }
.sb-cap { padding: 0 12px; font-size: 11px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--text-disabled); margin: 18px 0 8px; }

/* Topbar */
.tb { position: sticky; top: 0; z-index: 30; background: rgba(255,255,255,.85); backdrop-filter: blur(8px); border-bottom: 1px solid var(--grey-200); padding: 14px 32px; display: flex; align-items: center; justify-content: space-between; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: 8px; border-radius: 8px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; border: none; transition: all .15s ease; }
.btn-primary { background: var(--primary-main); color: #fff; box-shadow: var(--shadow-primary); }
.btn-primary:hover { background: var(--primary-dark); }
.btn-outline { background: #fff; border: 1px solid var(--grey-300); color: var(--text-primary); }
.btn-outline:hover { background: var(--grey-100); }

/* Chips */
.chip { padding: 3px 10px; border-radius: 8px; font-size: 12px; font-weight: 700; display: inline-block; }
.chip-success { background: var(--success-lighter); color: var(--success-dark); }
.chip-warning { background: var(--warning-lighter); color: var(--warning-dark); }
.chip-error { background: var(--error-lighter); color: var(--error-dark); }
.chip-info { background: var(--info-lighter); color: var(--info-dark); }
.chip-default { background: var(--grey-200); color: var(--text-secondary); }

/* Tables */
.ztable { width: 100%; font-size: 14px; border-collapse: collapse; }
.ztable thead th { text-align: left; background: var(--grey-200); color: var(--text-secondary); font-weight: 600; padding: 14px 24px; font-size: 13px; }
.ztable thead th:first-child { border-top-left-radius: 12px; border-bottom-left-radius: 12px; }
.ztable thead th:last-child { border-top-right-radius: 12px; border-bottom-right-radius: 12px; }
.ztable tbody td { padding: 16px 24px; border-bottom: 1px solid var(--grey-200); }
.ztable tbody tr:last-child td { border-bottom: none; }

/* Inputs */
.zinput { width: 100%; background: #fff; border: 1px solid var(--grey-300); border-radius: 8px; padding: 10px 14px; font-size: 14px; color: var(--text-primary); outline: none; transition: border-color .15s, box-shadow .15s; }
.zinput:focus { border-color: var(--primary-main); box-shadow: 0 0 0 3px rgba(0,167,111,.12); }
.zinput::placeholder { color: var(--text-disabled); }

/* Tabs */
.ztabs { display: inline-flex; gap: 4px; background: var(--grey-200); padding: 4px; border-radius: 10px; }
.ztab { padding: 8px 16px; border-radius: 8px; font-size: 14px; font-weight: 600; color: var(--text-secondary); cursor: pointer; border: none; background: transparent; transition: all .15s; }
.ztab.active { background: #fff; color: var(--text-primary); box-shadow: var(--shadow-z8); }

/* Misc */
.pill-icon { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: var(--grey-300); border-radius: 8px; }
.muted { color: var(--text-secondary); }
.dim { color: var(--text-disabled); }

/* Responsive application shell */
.mobile-menu-button {
    display: none; width: 44px; height: 44px; padding: 0; flex: 0 0 44px;
    align-items: center; justify-content: center; border: 1px solid var(--grey-300);
    border-radius: 10px; background: #fff; color: var(--text-primary); cursor: pointer;
}
.mobile-nav-overlay {
    display: none; position: fixed; inset: 0; z-index: 990;
    background: rgba(20,26,33,.48); backdrop-filter: blur(2px);
}
.mobile-nav-overlay.visible { display: block; }
.mobile-nav-active { overflow: hidden !important; touch-action: none; }
.topbar-actions { display: flex; align-items: center; gap: 16px; min-width: 0; }
.topbar-search { min-width: 0; }
.flex > .zinput { min-width: 0; }
.modal-scroll-card { max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; }

@media (max-width: 1023px) {
    .sb {
        display: flex !important; position: fixed; inset: 0 auto 0 0; top: 0;
        width: min(86vw, 300px); height: 100dvh; z-index: 1000;
        transform: translateX(-105%); transition: transform .24s ease;
        box-shadow: 18px 0 48px rgba(20,26,33,.18); overscroll-behavior: contain;
        padding-top: max(18px, env(safe-area-inset-top));
        padding-bottom: max(18px, env(safe-area-inset-bottom));
    }
    .sb.mobile-open { transform: translateX(0); }
    .zoan-embedded .sb { display: none !important; }
    .mobile-menu-button { display: inline-flex; }
    .zoan-embedded .mobile-menu-button { display: none; }
    .tb {
        min-height: 64px; padding: 10px 14px; gap: 10px;
        padding-left: max(14px, env(safe-area-inset-left));
        padding-right: max(14px, env(safe-area-inset-right));
    }
    .tb-desktop-action { display: none !important; }
    .topbar-actions { gap: 8px; margin-left: auto; }
    main[style*="padding"] {
        padding: 20px 16px 32px !important;
        padding-left: max(16px, env(safe-area-inset-left)) !important;
        padding-right: max(16px, env(safe-area-inset-right)) !important;
    }
    main > .flex.items-center.justify-between { align-items: flex-start; flex-wrap: wrap; gap: 12px; }
    .zcard.p-6, .zcard.p-5 { padding: 18px; }
    .stat-card { padding: 18px; }
    .ztabs {
        display: flex; width: 100%; max-width: 100%; overflow-x: auto;
        overscroll-behavior-x: contain; scrollbar-width: none;
    }
    .ztabs::-webkit-scrollbar { display: none; }
    .ztab { flex: 0 0 auto; min-height: 42px; padding: 8px 14px; }
    .btn { min-height: 44px; justify-content: center; }
    .zinput, input, select, textarea { font-size: 16px !important; }
    .zinput { min-height: 44px; }
    [style*="position:fixed"][style*="inset:0"] { padding: 12px; }
    [style*="position:fixed"][style*="inset:0"] > .zcard,
    [style*="position:fixed"][style*="inset:0"] > div {
        max-width: 100% !important; max-height: calc(100dvh - 24px); overflow-y: auto;
        overscroll-behavior: contain;
    }

    /* Data tables become readable cards instead of forcing sideways zooming. */
    .ztable-responsive { display: block; padding: 8px 12px 12px; }
    .ztable-responsive thead { display: none; }
    .ztable-responsive tbody, .ztable-responsive tfoot { display: block; }
    .ztable-responsive tbody tr {
        display: block; margin: 8px 0 12px; padding: 8px 14px;
        border: 1px solid var(--grey-200); border-radius: 12px; background: #fff;
        box-shadow: 0 5px 16px rgba(145,158,171,.08);
    }
    .ztable-responsive tbody td {
        display: grid; grid-template-columns: minmax(92px, 38%) minmax(0, 1fr);
        gap: 12px; align-items: start; padding: 9px 0 !important;
        border-bottom: 1px solid var(--grey-200); text-align: right !important;
        overflow-wrap: anywhere; white-space: normal !important; max-width: none !important;
    }
    .ztable-responsive tbody td:last-child { border-bottom: 0; }
    .ztable-responsive tbody td::before {
        content: attr(data-label); text-align: left; color: var(--text-secondary);
        font-size: 12px; font-weight: 700; line-height: 1.5;
    }
    .ztable-responsive tbody td[colspan] { display: block; text-align: center !important; }
    .ztable-responsive tbody td[colspan]::before { content: none; }
    .ztable-responsive tfoot tr { display: grid; grid-template-columns: 1fr auto; gap: 12px; padding: 12px 14px; border-radius: 12px; }
    .ztable-responsive tfoot td { display: none; padding: 0 !important; }
    .ztable-responsive tfoot td[colspan], .ztable-responsive tfoot td[id] { display: block; text-align: right !important; }
}

@media (max-width: 639px) {
    h1.text-2xl { font-size: 1.35rem; line-height: 1.75rem; }
    h3.text-lg { font-size: 1rem; line-height: 1.5rem; }
    .topbar-search { display: none !important; }
    .topbar-actions { width: auto; }
    #tbProfileMenu { position: fixed !important; top: 66px !important; left: 12px !important; right: 12px !important; min-width: 0 !important; width: auto !important; }
    .grid.grid-cols-2:not(.mobile-keep-two) { grid-template-columns: minmax(0, 1fr); }
    .flex.gap-3, .flex.gap-4 { row-gap: 10px; }
    main > .flex.items-center.justify-between > .flex { width: 100%; flex-wrap: wrap; }
    main > .flex.items-center.justify-between > .flex .btn { flex: 1 1 auto; }
    #src-range > .flex { flex-direction: column; }
    #src-range > .flex > span { display: none; }
    #src-range > .flex > .zinput { width: 100%; }
    #itemsList > .flex > select { min-width: 0; }
    .ztable-responsive tbody td { grid-template-columns: minmax(82px, 34%) minmax(0, 1fr); }
}

@media (max-width: 374px) {
    main[style*="padding"] { padding-left: 12px !important; padding-right: 12px !important; }
    .zcard.p-6, .zcard.p-5, .stat-card { padding: 15px; }
    .btn { padding-left: 12px; padding-right: 12px; }
}
