@font-face {
    font-family: "DM Sans";
    font-style: normal;
    font-weight: 400 500;
    font-display: swap;
    src: url("/assets/fonts/dm-sans-latin-400-600.woff2") format("woff2");
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    --bg: #f6f8f7;
    --surface: #ffffff;
    --surface-2: #f9fbf9;
    --text: #102828;
    --muted: #61706e;
    --border: #dfe8e4;
    --accent: #39b957;
    --accent-strong: #102828;
    --accent-soft: #e8f9eb;
    --good: #279347;
    --good-bg: #e8f9eb;
    --notice: #b76b08;
    --notice-bg: #fff4df;
    --danger: #cf2e3a;
    --danger-bg: #fde8eb;
    --shadow: 0 12px 30px rgba(16, 40, 40, 0.08);
    --radius: 8px;
    font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    height: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "DM Sans", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-weight: 400;
    font-size: 13px;
    line-height: 1.45;
    overflow: hidden;
}

strong,
b {
    font-weight: 450;
}

a {
    color: inherit;
    text-decoration: none;
}

button,
input,
textarea {
    font: inherit;
}

.app-shell {
    height: 100vh;
    display: grid;
    grid-template-columns: 252px minmax(0, 1fr);
    overflow: hidden;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    min-height: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    box-shadow: 10px 0 26px rgba(16, 40, 40, 0.08);
    padding: 22px 18px;
    display: flex;
    flex-direction: column;
    gap: 24px;
    overflow: auto;
    scrollbar-gutter: stable;
}

.brand {
    display: inline-flex;
    align-items: center;
    width: fit-content;
}

.brand-logo {
    display: block;
    width: 156px;
    height: auto;
}

.brand-logo-large {
    width: 190px;
}

.nav-list {
    display: grid;
    gap: 4px;
}

.nav-list a {
    min-height: 40px;
    padding: 0 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    border-radius: 7px;
    color: #314052;
    font-weight: 450;
}

.nav-list a:hover,
.nav-list a.is-active {
    background: var(--accent-soft);
    color: var(--accent-strong);
}

.nav-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    color: #657486;
}

.icon {
    flex: 0 0 auto;
    width: 17px;
    height: 17px;
    stroke-width: 1.7;
}

.icon-button .icon,
.primary-button .icon,
.secondary-button .icon {
    width: 16px;
    height: 16px;
}

.status-icon {
    width: 19px;
    height: 19px;
    color: var(--good);
}

.sync-card {
    margin-top: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    display: grid;
    gap: 8px;
    background: var(--surface-2);
}

.sync-card small {
    color: var(--muted);
}

.status-dot,
.notification-dot {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 12px;
    height: 12px;
    border-radius: 50%;
}

.status-dot.good {
    background: var(--good);
}

.notification-dot {
    width: 22px;
    height: 22px;
    background: var(--danger);
    color: white;
    font-size: 12px;
    font-weight: 450;
}

.main {
    min-width: 0;
    min-height: 0;
    height: 100vh;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr);
    overflow: hidden;
}

.topbar {
    height: 72px;
    padding: 0 28px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    position: sticky;
    top: 0;
    z-index: 10;
    backdrop-filter: blur(12px);
}

.global-search {
    width: min(680px, 52vw);
    position: relative;
}

.table-search,
.inline-search {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
}

.global-search input,
.inline-search input,
.table-search input,
.form-stack input,
.comment-form textarea {
    width: 100%;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 7px;
    padding: 11px 13px;
    outline: none;
    color: var(--text);
}

.global-search input,
.inline-search input,
.table-search input {
    padding-left: 38px;
}

.global-search input:focus,
.inline-search input:focus,
.table-search input:focus,
.form-stack input:focus,
.comment-form textarea:focus {
    border-color: #68d870;
    box-shadow: 0 0 0 3px rgba(104, 216, 112, 0.16);
}

.global-search kbd {
    position: absolute;
    right: 10px;
    top: 9px;
    border: 1px solid var(--border);
    border-radius: 5px;
    padding: 2px 7px;
    color: var(--muted);
    background: #f7f9fb;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-chip {
    display: grid;
    line-height: 1.1;
}

.user-chip small,
.page-head p,
.panel-title span,
.activity-list span,
.record-card small {
    color: var(--muted);
}

.primary-button,
.secondary-button,
.icon-button {
    border: 1px solid transparent;
    border-radius: 7px;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 0 14px;
    cursor: pointer;
    font-weight: 450;
}

.primary-button {
    background: var(--accent);
    color: white;
    box-shadow: 0 8px 16px rgba(57, 185, 87, 0.18);
}

.primary-button:hover {
    background: var(--accent-strong);
}

.secondary-button,
.icon-button {
    background: var(--surface);
    border-color: var(--border);
    color: #1f384a;
}

.full {
    width: 100%;
}

.content-grid,
.record-layout {
    padding: 28px;
    min-height: 0;
    overflow: hidden;
}

.content-grid {
    display: grid;
    gap: 22px;
    grid-template-rows: auto auto minmax(0, 1fr);
}

.two-row-page {
    grid-template-rows: auto minmax(0, 1fr);
}

.dashboard-page,
.records-page,
.sync-page,
.settings-page {
    height: 100%;
}

.sync-page > .table-panel {
    grid-row: 3;
}

.page-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 24px;
}

.page-head.compact {
    align-items: center;
    margin: 12px 0 18px;
}

h1,
h2,
p {
    margin-top: 0;
}

h1 {
    margin-bottom: 6px;
    font-size: 26px;
    font-weight: 450;
    line-height: 1.18;
}

h2 {
    margin-bottom: 0;
    font-size: 15px;
    font-weight: 450;
}

.metrics-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 16px;
}

.metric,
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.metric {
    padding: 20px;
    display: grid;
    gap: 6px;
}

.metric span {
    color: #4f5d6d;
}

.metric strong {
    font-size: 30px;
    font-weight: 450;
    line-height: 1;
}

.metric small {
    color: var(--good);
    font-weight: 450;
}

.metric.danger small {
    color: var(--danger);
}

.metric.notice small {
    color: var(--notice);
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: stretch;
    min-height: 0;
    height: 100%;
}

.panel {
    overflow: hidden;
}

.table-panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
    height: 100%;
    overflow: hidden;
}

.table-scroll {
    min-height: 0;
    flex: 1 1 auto;
    overflow: auto;
    scrollbar-gutter: stable;
}

.panel-toolbar,
.panel-title {
    min-height: 56px;
    padding: 12px 14px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.panel-toolbar-main {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.panel-title {
    align-items: flex-start;
}

.panel-title h2 {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.table-search,
.inline-search {
    display: flex;
    gap: 10px;
}

.table-search {
    width: min(360px, 100%);
}

.inline-search {
    width: min(520px, 100%);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    table-layout: auto;
}

.data-table th,
.data-table td {
    padding: 12px 14px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
    white-space: nowrap;
}

.data-table th {
    font-size: 11.5px;
    color: #596779;
    font-weight: 450;
    background: #fbfcfd;
    position: sticky;
    top: 0;
    z-index: 2;
}

.data-table tr:hover td {
    background: #f7fbfc;
}

.data-table tr {
    cursor: default;
}

.pill {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 0 9px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 450;
}

.segmented-control {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 3px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f7faf8;
}

.segmented-control a {
    min-height: 30px;
    padding: 0 12px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    color: #536071;
    font-weight: 450;
}

.segmented-control a:hover,
.segmented-control a.is-active {
    color: var(--accent-strong);
    background: var(--surface);
    box-shadow: 0 3px 10px rgba(16, 40, 40, 0.07);
}

.pill.good {
    color: var(--good);
    background: var(--good-bg);
}

.pill.danger {
    color: var(--danger);
    background: var(--danger-bg);
}

.pill.notice {
    color: var(--notice);
    background: var(--notice-bg);
}

.pill.neutral {
    color: #536071;
    background: #eef2f5;
}

.side-panel,
.record-aside,
.settings-grid {
    display: grid;
    gap: 16px;
    min-height: 0;
}

.side-panel {
    height: 100%;
    overflow: auto;
    scrollbar-gutter: stable;
}

.record-card {
    display: grid;
    gap: 4px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.record-card:hover {
    background: #f7fbfc;
}

.activity-list {
    display: grid;
}

.activity-list > div {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: grid;
    gap: 4px;
}

.activity-list p {
    margin: 5px 0 0;
}

.tabs {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 2px;
}

.tabs a {
    flex: 0 0 auto;
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 7px;
    padding: 9px 12px;
    font-weight: 450;
    color: #405064;
}

.tabs a.is-active {
    color: var(--accent-strong);
    background: var(--accent-soft);
    border-color: #b9edc1;
}

.text-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--accent-strong);
    font-weight: 450;
}

.record-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 400px;
    gap: 18px;
    align-items: start;
    overflow: auto;
}

.detail-grid {
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.detail-item {
    border: 1px solid var(--border);
    border-radius: 7px;
    padding: 12px;
    display: grid;
    gap: 5px;
    min-width: 0;
}

.detail-item span {
    color: var(--muted);
    font-size: 12px;
    font-weight: 450;
}

.detail-item strong {
    overflow-wrap: anywhere;
}

.comment-form {
    padding: 16px;
    display: grid;
    gap: 10px;
    border-bottom: 1px solid var(--border);
}

.comment-form textarea {
    min-height: 96px;
    resize: vertical;
}

.settings-grid {
    grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
    height: 100%;
}

.settings-grid .panel {
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.permission-list {
    min-height: 0;
    overflow: auto;
    scrollbar-gutter: stable;
}

.permission-list {
    display: grid;
}

.permission-list > div {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    gap: 12px;
}

.permission-list span {
    color: var(--muted);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12px;
}

.compact-table th,
.compact-table td {
    white-space: normal;
}

.auth-body {
    min-height: 100vh;
    background: linear-gradient(135deg, #f6fafb 0%, #edf3f6 100%);
}

.login-screen {
    height: 100vh;
    display: grid;
    grid-template-columns: minmax(320px, 460px) minmax(0, 1fr);
}

.login-panel,
.login-context {
    padding: clamp(28px, 6vw, 70px);
}

.login-panel {
    background: var(--surface);
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 20px;
    box-shadow: var(--shadow);
}

.login-brand {
    margin-bottom: 20px;
}

.login-panel h1 {
    font-size: 32px;
    font-weight: 450;
    letter-spacing: 0;
}

.login-panel p {
    color: var(--muted);
}

.form-stack {
    display: grid;
    gap: 14px;
}

.form-stack label {
    display: grid;
    gap: 7px;
    font-weight: 450;
}

.login-context {
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.login-context ul {
    display: grid;
    gap: 12px;
    color: #314052;
    padding-left: 18px;
}

.alert {
    background: #fff6e7;
    color: #7a4700;
    border: 1px solid #f2d39b;
    border-radius: 7px;
    padding: 12px 14px;
    font-weight: 450;
}

@media (max-width: 1100px) {
    body {
        overflow: auto;
    }

    .app-shell,
    .workspace,
    .record-layout,
    .settings-grid,
    .login-screen {
        grid-template-columns: 1fr;
    }

    .app-shell,
    .main,
    .content-grid,
    .dashboard-page,
    .records-page,
    .workspace,
    .login-screen {
        height: auto;
        min-height: 0;
        overflow: visible;
    }

    .sidebar {
        position: static;
        height: auto;
        border-right: 0;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 8px 22px rgba(16, 40, 40, 0.06);
    }

    .nav-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .sync-card {
        margin-top: 0;
    }

    .topbar {
        position: static;
        height: auto;
        padding: 14px;
        align-items: stretch;
        flex-direction: column;
    }

    .global-search {
        width: 100%;
    }

    .metrics-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 720px) {
    .content-grid,
    .record-layout {
        padding: 16px;
    }

    .page-head,
    .panel-toolbar,
    .panel-toolbar-main,
    .topbar-actions,
    .table-search,
    .inline-search {
        flex-direction: column;
        align-items: stretch;
    }

    .global-search kbd {
        display: none;
    }

    .table-search,
    .inline-search {
        width: 100%;
    }

    .table-search .search-icon,
    .inline-search .search-icon {
        top: 22px;
    }

    .metrics-grid,
    .detail-grid {
        grid-template-columns: 1fr;
    }

    .sync-card {
        display: none;
    }

    .data-table {
        min-width: 760px;
    }

    .login-panel h1 {
        font-size: 28px;
    }
}
