:root {
    --teal: #08a8a8;
    --teal-dark: #067e85;
    --teal-soft: #dff8f7;
    --ink: #17313d;
    --muted: #6d7a83;
    --line: #e3e9ec;
    --surface: #ffffff;
    --background: #f5f8f9;
    --danger: #d84949;
    --warning: #ef8d25;
    --success: #1a9b62;
    --purple: #6a45df;
    --blue: #267be5;
    --shadow: 0 8px 24px rgba(24, 53, 66, .09);
    --radius: 18px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--background); }
body {
    margin: 0;
    min-height: 100%;
    background: var(--background);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--teal-dark); text-decoration: none; }
a:hover { text-decoration: none; }
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    display: grid;
    grid-template-columns: 48px 1fr 48px;
    align-items: center;
    height: calc(68px + env(safe-area-inset-top, 0px));
    padding: env(safe-area-inset-top, 0px) 12px 0;
    background: linear-gradient(135deg, #0bb4ad, #049ba7);
    color: white;
    box-shadow: 0 3px 14px rgba(5, 122, 129, .2);
}
.brand { color: white; font-size: 1.28rem; font-weight: 800; text-align: center; letter-spacing: -.02em; }
.icon-button {
    width: 44px;
    height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    border-radius: 14px;
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.icon-button:hover { background: rgba(255,255,255,.13); }
.section-tabs {
    position: sticky;
    top: calc(68px + env(safe-area-inset-top, 0px));
    z-index: 35;
    display: flex;
    overflow-x: auto;
    scrollbar-width: none;
    background: white;
    border-bottom: 1px solid var(--line);
    padding: 0 8px;
}
.section-tabs::-webkit-scrollbar { display: none; }
.section-tabs a {
    flex: 0 0 auto;
    padding: 15px 14px 13px;
    color: #647079;
    font-size: .76rem;
    font-weight: 800;
    letter-spacing: .055em;
    text-transform: uppercase;
    border-bottom: 3px solid transparent;
}
.section-tabs a.active { color: var(--teal); border-bottom-color: var(--teal); }

.app-content { min-height: 100vh; padding-bottom: calc(84px + var(--safe-bottom)); }
.page-shell { width: 100%; max-width: 1180px; margin: 0 auto; padding: 20px 14px 30px; }
.page-heading { display: flex; gap: 12px; justify-content: space-between; align-items: flex-start; margin-bottom: 16px; }
.page-heading h1 { margin: 0; font-size: 1.55rem; letter-spacing: -.025em; }
.page-heading p { margin: 5px 0 0; color: var(--muted); }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

.card {
    background: var(--surface);
    border: 1px solid rgba(217, 226, 230, .9);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
}
.card + .card { margin-top: 14px; }
.card h2, .card h3 { margin-top: 0; }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 14px; }
.card-title h2 { margin: 0; font-size: 1.15rem; }

.stat-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.stat-card {
    min-height: 142px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 14px 8px;
    background: white;
    border: 1px solid #e5eaed;
    border-radius: 15px;
    box-shadow: 0 5px 14px rgba(25, 57, 72, .08);
}
.stat-icon { width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 6px; }
.stat-icon svg { width: 22px; height: 22px; }
.stat-number { font-size: 2.25rem; line-height: 1; font-weight: 800; letter-spacing: -.04em; }
.stat-label { margin-top: 10px; color: #68727b; font-size: .76rem; font-weight: 800; letter-spacing: .035em; text-transform: uppercase; }
.stat-teal .stat-icon { color: var(--teal-dark); background: var(--teal-soft); }
.stat-teal .stat-number { color: #069ba7; }
.stat-orange .stat-icon { color: #f07818; background: #fff0df; }
.stat-orange .stat-number { color: #f07818; }
.stat-purple .stat-icon { color: var(--purple); background: #eee8ff; }
.stat-purple .stat-number { color: var(--purple); }
.stat-blue .stat-icon { color: var(--blue); background: #e5f0ff; }
.stat-blue .stat-number { color: var(--blue); }
.stat-green .stat-icon { color: var(--success); background: #e2f8e9; }
.stat-green .stat-number { color: var(--success); }

.activity-list { overflow: hidden; border: 1px solid var(--line); border-radius: 15px; background: white; }
.activity-row { display: grid; grid-template-columns: 46px minmax(0,1fr) auto; align-items: center; gap: 11px; padding: 13px; border-bottom: 1px solid var(--line); color: var(--ink); }
.activity-row:last-child { border-bottom: 0; }
.activity-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; color: white; background: var(--teal); }
.activity-icon svg { width: 21px; height: 21px; }
.activity-text strong { display: block; font-size: .95rem; }
.activity-text small, .activity-time { color: var(--muted); font-size: .76rem; }
.activity-time { white-space: nowrap; }

.button, button.button {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 16px;
    border: 0;
    border-radius: 13px;
    background: var(--teal);
    color: white;
    font-weight: 750;
    cursor: pointer;
    box-shadow: 0 5px 14px rgba(8, 168, 168, .2);
}
.button svg { width: 19px; height: 19px; }
.button-secondary { background: white; color: var(--ink); border: 1px solid var(--line); box-shadow: none; }
.button-danger { background: var(--danger); }
.button-warning { background: var(--warning); }
.button-small { min-height: 38px; padding: 8px 12px; border-radius: 11px; font-size: .88rem; }
.button-block { width: 100%; }

.form-card { max-width: 900px; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field label { color: #344b56; font-size: .88rem; font-weight: 750; }
.field small { color: var(--muted); }
.input, input[type="text"], input[type="email"], input[type="password"], input[type="url"], input[type="tel"], input[type="date"], input[type="datetime-local"], input[type="number"], select, textarea {
    width: 100%;
    min-height: 48px;
    border: 1px solid #ccd8dd;
    border-radius: 13px;
    background: white;
    color: var(--ink);
    padding: 11px 12px;
    outline: none;
}
textarea { min-height: 130px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(8,168,168,.12); }
.form-section { padding: 18px 0; border-bottom: 1px solid var(--line); }
.form-section:first-child { padding-top: 0; }
.form-section:last-child { border-bottom: 0; padding-bottom: 0; }
.form-section h2 { margin: 0 0 12px; font-size: 1.05rem; }
.form-actions { position: sticky; bottom: calc(72px + var(--safe-bottom)); z-index: 10; display: flex; gap: 10px; margin-top: 18px; padding: 12px; background: rgba(245,248,249,.94); backdrop-filter: blur(12px); border-radius: 16px; }
.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 15px; min-height: 54px; }
.switch { position: relative; width: 54px; height: 30px; flex: 0 0 54px; }
.switch input { position: absolute; opacity: 0; }
.switch span { position: absolute; inset: 0; border-radius: 999px; background: #cfd8dc; transition: .2s; }
.switch span:after { content: ""; position: absolute; width: 24px; height: 24px; left: 3px; top: 3px; border-radius: 50%; background: white; box-shadow: 0 2px 6px rgba(0,0,0,.2); transition: .2s; }
.switch input:checked + span { background: var(--teal); }
.switch input:checked + span:after { transform: translateX(24px); }

.search-row { display: flex; gap: 9px; margin-bottom: 14px; }
.search-box { position: relative; flex: 1; }
.search-box svg { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); width: 19px; color: var(--muted); }
.search-box input { padding-left: 42px; }
.filter-bar { display: grid; grid-template-columns: 1fr; gap: 9px; margin-bottom: 14px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; align-items: center; padding: 15px; border: 1px solid var(--line); border-radius: 15px; background: white; color: var(--ink); }
.list-card:hover { border-color: #b8d8db; box-shadow: 0 4px 13px rgba(8,168,168,.08); }
.list-card h3 { margin: 0 0 4px; font-size: 1rem; }
.list-card p { margin: 0; color: var(--muted); font-size: .88rem; }
.list-meta { display: flex; flex-wrap: wrap; gap: 7px 12px; margin-top: 8px; color: var(--muted); font-size: .78rem; }
.list-chevron { color: #98a5ab; font-size: 1.5rem; }

.badge { display: inline-flex; align-items: center; min-height: 25px; padding: 3px 9px; border-radius: 999px; background: #edf1f2; color: #56636a; font-size: .72rem; font-weight: 800; }
.badge-success { background: #e0f7ea; color: #157748; }
.badge-warning { background: #fff0dc; color: #a45b10; }
.badge-danger { background: #ffe5e5; color: #ae3333; }
.badge-info { background: #e2f4f7; color: #087780; }
.badge-purple { background: #eee8ff; color: #5d3ac6; }

.detail-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.detail-item { padding: 12px 0; border-bottom: 1px solid var(--line); }
.detail-item:last-child { border-bottom: 0; }
.detail-item dt { color: var(--muted); font-size: .76rem; font-weight: 800; text-transform: uppercase; letter-spacing: .04em; }
.detail-item dd { margin: 4px 0 0; font-weight: 650; word-break: break-word; }
.profile-head { display: grid; grid-template-columns: 58px 1fr; gap: 14px; align-items: center; }
.profile-avatar { width: 58px; height: 58px; border-radius: 18px; display: grid; place-items: center; background: var(--teal-soft); color: var(--teal-dark); font-size: 1.4rem; font-weight: 900; }
.profile-head h1 { margin: 0; font-size: 1.45rem; }
.profile-head p { margin: 4px 0 0; color: var(--muted); }
.tabs { display: flex; gap: 5px; overflow-x: auto; padding: 5px; margin: 14px 0; border-radius: 14px; background: #eaf0f2; }
.tabs a { flex: 0 0 auto; padding: 9px 12px; border-radius: 10px; color: #607078; font-size: .83rem; font-weight: 750; }
.tabs a.active { background: white; color: var(--teal-dark); box-shadow: 0 2px 8px rgba(25,57,72,.08); }

.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 14px; }
table { width: 100%; border-collapse: collapse; min-width: 720px; background: white; }
th, td { padding: 12px 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: #68757c; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; background: #f8fafb; }
tr:last-child td { border-bottom: 0; }

.flash { max-width: 1180px; margin: 12px auto 0; padding: 13px 16px; border-radius: 13px; font-weight: 650; }
.flash-success { background: #dff7e9; color: #176e45; }
.flash-warning { background: #fff0d9; color: #92510b; }
.flash-error { background: #ffe3e3; color: #a02f2f; }
.flash-info { background: #e1f5f7; color: #08767e; }
.empty-state { text-align: center; padding: 38px 22px; }
.empty-state h1, .empty-state h2 { margin-top: 0; }
.empty-state p { color: var(--muted); }

.bottom-nav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 45;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    min-height: calc(66px + var(--safe-bottom));
    padding: 5px 4px var(--safe-bottom);
    background: rgba(255,255,255,.97);
    border-top: 1px solid var(--line);
    box-shadow: 0 -4px 18px rgba(20,49,61,.08);
    backdrop-filter: blur(16px);
}
.nav-link { min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 6px 2px; border: 0; background: transparent; color: #7a858b; font-size: .67rem; font-weight: 700; cursor: pointer; }
.nav-link.active { color: var(--teal); }
.nav-icon { height: 25px; display: grid; place-items: center; }
.nav-icon svg { width: 23px; height: 23px; }

.drawer { position: fixed; inset: 0; z-index: 100; visibility: hidden; }
.drawer.open { visibility: visible; }
.drawer-backdrop { position: absolute; inset: 0; background: rgba(10,24,30,.46); opacity: 0; transition: .2s; }
.drawer.open .drawer-backdrop { opacity: 1; }
.drawer-panel { position: absolute; top: 0; left: 0; bottom: 0; width: min(88vw, 340px); padding-top: env(safe-area-inset-top); background: white; transform: translateX(-102%); transition: .22s ease; box-shadow: 15px 0 40px rgba(0,0,0,.18); overflow-y: auto; }
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-head { display: grid; grid-template-columns: 48px 1fr 40px; gap: 10px; align-items: center; padding: 18px 14px; border-bottom: 1px solid var(--line); }
.drawer-head .avatar { width: 48px; height: 48px; border-radius: 15px; display: grid; place-items: center; background: var(--teal); color: white; font-weight: 900; }
.drawer-head strong, .drawer-head small { display: block; overflow: hidden; text-overflow: ellipsis; }
.drawer-head small { color: var(--muted); }
.drawer-nav { padding: 10px; }
.drawer-nav .nav-link { flex-direction: row; justify-content: flex-start; gap: 12px; min-height: 48px; padding: 10px 12px; border-radius: 12px; font-size: .94rem; }
.drawer-nav .nav-link.active { background: var(--teal-soft); }

.public-layout { background: linear-gradient(155deg, #e6fbfa 0, #f5f8f9 44%, #eef2f4 100%); }
.public-layout .app-content { padding: 0; }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px 16px; }
.auth-card { width: min(100%, 450px); padding: 25px; }
.auth-logo { width: 64px; height: 64px; display: grid; place-items: center; margin-bottom: 18px; border-radius: 20px; background: linear-gradient(135deg, #0bb4ad, #049ba7); color: white; box-shadow: 0 10px 25px rgba(8,168,168,.25); }
.auth-logo svg { width: 32px; height: 32px; }
.auth-card h1 { margin: 0; font-size: 1.7rem; }
.auth-card > p { margin: 6px 0 20px; color: var(--muted); }
.auth-links { display: flex; justify-content: space-between; align-items: center; margin-top: 15px; font-size: .9rem; }

.module-card { position: relative; }
.module-card .module-status { position: absolute; top: 14px; right: 14px; }
.code-note { overflow-x: auto; padding: 13px; border-radius: 12px; background: #172c36; color: #dff8f7; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .82rem; }
.warning-box { padding: 13px; border: 1px solid #f0cf9d; border-radius: 13px; background: #fff8ec; color: #86511a; }
.info-box { padding: 13px; border: 1px solid #bce1e4; border-radius: 13px; background: #effbfb; color: #176b72; }
.danger-zone { border-color: #efc0c0; }

@media (min-width: 700px) {
    .page-shell { padding: 28px 24px 40px; }
    .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
    .filter-bar { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .detail-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); column-gap: 28px; }
    .form-actions { position: static; background: transparent; padding: 0; }
}

@media (min-width: 980px) {
    .topbar { padding-left: 24px; padding-right: 24px; }
    .brand { text-align: left; }
    .section-tabs { justify-content: center; top: calc(68px + env(safe-area-inset-top, 0px)); }
    .app-content { padding-bottom: 0; }
    .bottom-nav { display: none; }
    .stat-grid { grid-template-columns: repeat(6, minmax(0,1fr)); }
    .stat-card { min-height: 155px; }
    .desktop-grid { display: grid; grid-template-columns: minmax(0, 2fr) minmax(320px, 1fr); gap: 18px; align-items: start; }
}
