:root {
    --bg: #f4f7fb;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #142033;
    --muted: #5f6f85;
    --border: #dce4ef;
    --primary: #0f766e;
    --primary-dark: #115e59;
    --danger: #b42318;
    --danger-bg: #fef3f2;
    --success: #067647;
    --success-bg: #ecfdf3;
    --warning: #b54708;
    --warning-bg: #fffaeb;
    --shadow: 0 18px 50px rgba(15, 23, 42, 0.08);
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: "Manrope", sans-serif;
    color: var(--text);
    background:
        radial-gradient(circle at top left, rgba(15, 118, 110, 0.16), transparent 28%),
        radial-gradient(circle at bottom right, rgba(59, 130, 246, 0.12), transparent 24%),
        var(--bg);
}

.app-body {
    height: 100vh;
    overflow: hidden;
}

button,
input,
select,
textarea {
    font: inherit;
}

a {
    color: inherit;
}

button {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    cursor: pointer;
    background: var(--primary);
    color: #fff;
    font-weight: 700;
    transition: transform 0.16s ease, opacity 0.16s ease, background 0.16s ease;
}

button:hover {
    transform: translateY(-1px);
}

button:disabled {
    opacity: 0.65;
    cursor: wait;
    transform: none;
}

.ghost-button {
    background: #e8f5f3;
    color: var(--primary-dark);
}

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

.small-button {
    padding: 8px 12px;
    font-size: 0.87rem;
}

.full-width {
    width: 100%;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
    color: var(--text);
    padding: 12px 14px;
}

textarea {
    resize: vertical;
}

label {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 0.92rem;
}

.stack-form,
.product-form,
.movement-form {
    display: grid;
    gap: 16px;
}

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

.form-grid {
    display: grid;
    gap: 16px;
}

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

.form-grid.three-up {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.full-span {
    grid-column: 1 / -1;
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-layout {
    width: min(1120px, 100%);
    display: grid;
    grid-template-columns: 1.25fr 0.9fr;
    gap: 24px;
    align-items: stretch;
}

.auth-hero,
.auth-card,
.panel,
.stat-card,
.sidebar,
.modal-card,
.state-card {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid rgba(220, 228, 239, 0.85);
    border-radius: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.auth-hero,
.auth-card,
.state-card {
    padding: 32px;
}

.auth-hero h1,
.state-card h1 {
    margin: 0 0 16px;
    font-size: clamp(2rem, 5vw, 4rem);
    line-height: 0.96;
}

.hero-copy {
    max-width: 56ch;
    color: var(--muted);
    line-height: 1.7;
}

.auth-logo {
    width: min(340px, 100%);
    margin-bottom: 18px;
    display: block;
}

.auth-card-logo {
    width: 64px;
    height: 64px;
    object-fit: contain;
}

.hero-points {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-top: 24px;
}

.hero-points span,
.badge,
.checkbox-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.88rem;
}

.hero-points span {
    background: #edf8f7;
    color: var(--primary-dark);
}

.badge-success {
    background: var(--success-bg);
    color: var(--success);
}

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

.badge-warning {
    background: var(--warning-bg);
    color: var(--warning);
}

.badge-neutral {
    background: #eef4ff;
    color: #2f5fa7;
}

.section-kicker,
.eyebrow {
    margin: 0 0 10px;
    color: var(--primary-dark);
    text-transform: uppercase;
    letter-spacing: 0.16em;
    font-size: 0.75rem;
    font-weight: 800;
}

.status-text {
    margin: 0;
    min-height: 24px;
    color: var(--muted);
    line-height: 1.5;
}

.app-shell {
    height: 100vh;
    display: grid;
    grid-template-columns: 280px minmax(0, 1fr);
    gap: 20px;
    padding: 20px;
}

.sidebar,
.main-panel {
    min-height: 0;
}

.sidebar {
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    position: sticky;
    top: 20px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
}

.brand {
    display: grid;
    gap: 14px;
}

.brand-logo {
    width: min(180px, 100%);
    display: block;
}

.brand-copy {
    display: grid;
    gap: 4px;
}

.sidebar-nav {
    display: grid;
    gap: 10px;
    margin-top: 24px;
}

.nav-link {
    width: 100%;
    justify-content: flex-start;
    text-align: left;
    background: transparent;
    color: var(--muted);
    border: 1px solid transparent;
}

.nav-link.is-active {
    background: #eff8ff;
    border-color: #d0e5f8;
    color: #1447ad;
}

.main-panel {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 18px;
    max-height: calc(100vh - 40px);
    min-height: 0;
    overflow: hidden;
}

.topbar,
.panel {
    padding: 24px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(220, 228, 239, 0.85);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.topbar-identity {
    display: flex;
    align-items: center;
    gap: 16px;
    min-width: 0;
}

.topbar-logo {
    width: 60px;
    height: 60px;
    object-fit: contain;
    flex-shrink: 0;
}

.topbar h1,
.panel h2 {
    margin: 0;
}

.content-stack {
    display: grid;
    gap: 20px;
    min-height: 0;
    overflow-y: auto;
    padding-right: 6px;
    scrollbar-gutter: stable;
    scroll-behavior: smooth;
    overscroll-behavior: contain;
}

.view {
    display: none;
    gap: 20px;
}

.view.is-active {
    display: grid;
}

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

.dashboard-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.stat-card {
    padding: 20px;
}

.stat-card span {
    display: block;
    color: var(--muted);
    margin-bottom: 10px;
}

.stat-card strong {
    font-size: 2rem;
}

.panel-heading,
.toolbar,
.button-row,
.inline-actions,
.movement-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.inline-actions a {
    text-decoration: none;
}

.inline-actions a.ghost-button,
.inline-actions a.danger-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 700;
}

.inline-actions a.small-button {
    padding: 8px 12px;
    font-size: 0.87rem;
}

.toolbar {
    margin-bottom: 18px;
}

.compact-toolbar {
    margin-bottom: 0;
}

.toolbar > input[type="search"] {
    flex: 2 1 280px;
}

.toolbar > select,
.toolbar > label {
    flex: 1 1 180px;
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 14px 10px;
    text-align: left;
    border-bottom: 1px solid var(--border);
    font-size: 0.94rem;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-weight: 700;
}

.category-path {
    font-weight: 700;
}

.table-meta {
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.84rem;
}

.empty-state {
    margin-top: 16px;
    padding: 18px;
    border: 1px dashed var(--border);
    border-radius: 16px;
    color: var(--muted);
    background: var(--surface-muted);
}

.checkbox-chip {
    background: #fff;
    border: 1px solid var(--border);
    color: var(--text);
}

.checkbox-chip input {
    width: auto;
    margin: 0;
}

.action-panel {
    background: linear-gradient(180deg, rgba(240, 253, 250, 0.9), rgba(255, 255, 255, 0.95));
}

.movement-preview {
    padding: 14px 16px;
    border-radius: 16px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
}

.party-selector-panel,
.party-history-card {
    display: grid;
    gap: 14px;
}

.party-history-card {
    padding: 18px;
    border-radius: 18px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.82);
}

.party-history-stats {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.operation-panel {
    display: grid;
    gap: 16px;
}

.operation-lines {
    display: grid;
    gap: 14px;
}

.operation-line {
    display: grid;
    gap: 14px;
    padding: 16px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.88);
}

.operation-line-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: 2.2fr 1fr 1fr auto;
    align-items: end;
}

.operation-line-preview {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--muted);
    font-size: 0.9rem;
}

.operation-line-warning {
    color: var(--warning);
    font-weight: 700;
}

.operation-line-danger {
    color: var(--danger);
    font-weight: 700;
}

.operation-detail-panel {
    display: grid;
    gap: 18px;
}

.detail-meta-grid,
.detail-two-column {
    display: grid;
    gap: 16px;
}

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

.detail-two-column {
    grid-template-columns: 1.3fr 1fr;
}

.compact-card,
.detail-card {
    padding: 20px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.88);
}

.compact-card {
    display: grid;
    gap: 10px;
}

.compact-card h3 {
    margin: 0;
    font-size: 1.15rem;
}

.muted-text {
    margin: 0;
    color: var(--muted);
}

.attachment-upload-row {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.attachment-upload-row input[type="file"] {
    flex: 1 1 260px;
}

.upload-dropzone {
    padding: 28px 24px;
    border-radius: 20px;
    border: 1px dashed #94b8d8;
    background: linear-gradient(180deg, #f7fcff, #fafdff);
    text-align: center;
    cursor: pointer;
    transition: border-color 0.16s ease, transform 0.16s ease, background 0.16s ease;
}

.upload-dropzone:hover,
.upload-dropzone.is-dragover {
    border-color: #0f766e;
    background: linear-gradient(180deg, #eefbf8, #ffffff);
    transform: translateY(-1px);
}

.upload-dropzone strong {
    display: block;
    margin-bottom: 8px;
    font-size: 1rem;
}

.import-stats {
    margin-bottom: 18px;
}

.import-note-list {
    display: grid;
    gap: 6px;
}

.import-note {
    font-size: 0.88rem;
    line-height: 1.45;
}

.import-note-error {
    color: var(--danger);
}

.import-note-warning {
    color: var(--warning);
}

.import-alert-stack {
    display: grid;
    gap: 0.75rem;
}

.import-alert {
    border: 1px solid rgba(185, 28, 28, 0.18);
    background: rgba(254, 242, 242, 0.96);
    color: #991b1b;
    border-radius: 14px;
    padding: 0.95rem 1rem;
    font-size: 0.95rem;
    line-height: 1.5;
}

.modal-card-wide {
    width: min(720px, calc(100vw - 32px));
}

.install-settings-card {
    margin-top: 20px;
    padding: 18px 20px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: linear-gradient(180deg, rgba(239, 248, 255, 0.72), rgba(255, 255, 255, 0.94));
    display: grid;
    gap: 14px;
}

.settings-logo-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 18px 20px;
    border-radius: 20px;
    border: 1px dashed var(--border);
    background: rgba(255, 255, 255, 0.92);
}

.settings-logo-preview {
    width: 160px;
    max-height: 88px;
    object-fit: contain;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: #fff;
    padding: 10px;
}

.install-settings-copy {
    display: grid;
    gap: 8px;
}

.install-settings-copy h3 {
    margin: 0;
}

.toast-root {
    position: fixed;
    right: 18px;
    bottom: 18px;
    display: grid;
    gap: 12px;
    z-index: 50;
}

.toast {
    min-width: 260px;
    max-width: 360px;
    padding: 14px 16px;
    border-radius: 16px;
    color: #fff;
    box-shadow: var(--shadow);
    animation: slideUp 0.2s ease;
}

.toast-success {
    background: linear-gradient(135deg, #067647, #0f766e);
}

.toast-error {
    background: linear-gradient(135deg, #b42318, #7a271a);
}

.toast.is-hidden {
    opacity: 0;
}

.modal-root {
    position: fixed;
    inset: 0;
    z-index: 60;
    display: grid;
    place-items: center;
}

.modal-root[hidden] {
    display: none !important;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
}

.modal-card {
    position: relative;
    z-index: 1;
    width: min(460px, calc(100% - 32px));
    padding: 24px;
}

.install-banner {
    position: fixed;
    right: 18px;
    bottom: 110px;
    z-index: 55;
    width: min(420px, calc(100vw - 32px));
    padding: 20px;
    border-radius: 22px;
    border: 1px solid rgba(220, 228, 239, 0.95);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    display: grid;
    gap: 14px;
    animation: slideUp 0.22s ease;
}

.install-banner[hidden] {
    display: none !important;
}

.install-banner-brand {
    display: flex;
    align-items: center;
    gap: 14px;
}

.install-banner-logo {
    width: 58px;
    height: 58px;
    object-fit: contain;
    flex-shrink: 0;
}

.install-banner-copy {
    display: grid;
    gap: 4px;
}

.install-banner-copy h3 {
    margin: 0;
}

.install-instructions {
    margin: 0;
    padding: 12px 14px;
    border-radius: 16px;
    background: #eef6ff;
    color: #1d4f91;
    line-height: 1.55;
}

.state-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.link-button {
    display: inline-flex;
    justify-content: center;
    text-decoration: none;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 1080px) {
    .app-body {
        height: auto;
        overflow: auto;
    }

    .app-shell,
    .auth-layout {
        grid-template-columns: 1fr;
        height: auto;
    }

    .sidebar,
    .main-panel {
        min-height: auto;
        max-height: none;
        overflow: visible;
    }

    .sidebar {
        position: static;
        top: auto;
        overflow: visible;
    }

    .install-banner {
        bottom: 18px;
    }

    .content-stack {
        overflow: visible;
        padding-right: 0;
    }

    .stats-grid,
    .dashboard-grid,
    .party-history-stats,
    .detail-meta-grid,
    .detail-two-column,
    .form-grid.two-up,
    .form-grid.three-up,
    .product-form,
    .movement-form {
        grid-template-columns: 1fr 1fr;
    }

    .dashboard-grid {
        grid-template-columns: 1fr;
    }

    .operation-line-grid {
        grid-template-columns: 1fr 1fr;
    }

    .settings-logo-card {
        flex-direction: column;
        align-items: stretch;
    }
}

@media (max-width: 780px) {
    .stats-grid,
    .dashboard-grid,
    .party-history-stats,
    .detail-meta-grid,
    .detail-two-column,
    .form-grid.two-up,
    .form-grid.three-up,
    .product-form,
    .movement-form {
        grid-template-columns: 1fr;
    }

    .operation-line-grid {
        grid-template-columns: 1fr;
    }

    .app-shell {
        padding: 12px;
        gap: 12px;
    }

    .topbar,
    .panel,
    .sidebar {
        padding: 18px;
    }

    .topbar-identity {
        gap: 12px;
    }

    .topbar-logo {
        width: 48px;
        height: 48px;
    }

    .install-banner {
        left: 12px;
        right: 12px;
        bottom: 12px;
        width: auto;
    }
}
