* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
}

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    gap: 32px;
    height: 56px;
    padding: 0 24px;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
}

.brand {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.main-nav {
    display: flex;
    gap: 4px;
    height: 100%;
}

.nav-tab {
    position: relative;
    height: 100%;
    padding: 0 14px;
    border: 0;
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition: color var(--speed) var(--ease);
}

.nav-tab:hover,
.nav-tab.active {
    color: var(--text);
}

.nav-tab.active::after {
    content: "";
    position: absolute;
    left: 14px;
    right: 14px;
    bottom: -1px;
    height: 2px;
    background: var(--accent);
}

.header-tools {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.page {
    max-width: 1400px;
    margin: 0 auto;
    padding: 28px 24px 60px;
}

.view {
    display: none;
}

.view.active {
    display: block;
}

.page-title {
    margin: 0 0 4px;
    font-size: 22px;
    font-weight: 700;
}

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

body.signed-out .main-nav,
body.signed-out .header-tools {
    display: none;
}

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

.panel-body {
    padding: 16px 18px;
}

.btn,
.btn-quiet {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--speed) var(--ease),
        border-color var(--speed) var(--ease),
        opacity var(--speed) var(--ease);
}

.btn {
    border: 1px solid var(--accent);
    background: var(--accent);
    color: var(--on-accent);
}

.btn:hover {
    opacity: 0.88;
}

.btn:disabled {
    opacity: 0.5;
    cursor: default;
}

.btn-quiet {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--text);
}

.btn-quiet:hover {
    border-color: var(--muted);
}

.btn-small {
    padding: 5px 10px;
    font-size: 13px;
}

.icon {
    display: inline-flex;
    width: 16px;
    height: 16px;
}

.icon svg {
    width: 100%;
    height: 100%;
}

.status {
    margin: 14px 0 0;
    font-weight: 600;
}

.status.good {
    color: var(--good);
}

.status.bad {
    color: var(--bad);
}

.user-menu {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-left: 12px;
    border-left: 1px solid var(--line);
}

.user-name {
    font-weight: 600;
}

.sign-in {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: calc(100vh - 56px - 88px);
}

.sign-in-panel {
    width: 100%;
    max-width: 380px;
}

.sign-in-panel .panel-body {
    padding: 28px 26px;
}

.sign-in-icon {
    display: inline-flex;
    margin-bottom: 14px;
    padding: 10px;
    border-radius: var(--radius);
    background: var(--surface-2);
    color: var(--accent);
}

.sign-in-icon .icon {
    width: 24px;
    height: 24px;
}

.sign-in-form {
    margin-top: 20px;
}

.sign-in-btn {
    justify-content: center;
    width: 100%;
}

.sign-in-hint {
    margin: 16px 0 0;
    font-size: 12px;
    color: var(--warn);
}

.page-head {
    margin-bottom: 18px;
}

.sub-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 18px;
}

.sub-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 7px 14px;
    border: 0;
    border-radius: var(--pill);
    background: transparent;
    color: var(--muted);
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    transition:
        background var(--speed) var(--ease),
        color var(--speed) var(--ease);
}

.sub-tab:hover {
    color: var(--text);
    background: var(--surface-2);
}

.sub-tab.active {
    background: var(--accent);
    color: var(--on-accent);
}

.count {
    min-width: 20px;
    padding: 1px 6px;
    border-radius: var(--pill);
    background: var(--surface-2);
    color: var(--text);
    font-size: 12px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.sub-tab.active .count {
    background: var(--on-accent);
    color: var(--accent);
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-bottom: 1px solid var(--line);
}

.panel-title {
    margin: 0;
    font-size: 15px;
    font-weight: 700;
}

.panel-note {
    margin: 4px 0 0;
    font-size: 13px;
    color: var(--muted);
}

.panel-tools {
    display: flex;
    align-items: center;
    gap: 8px;
}

.form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.form-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px 18px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
}

.field-wide {
    grid-column: 1 / -1;
}

.optional {
    font-weight: 400;
    opacity: 0.8;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: vvar(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 14px;
    font-weight: 400;
    transition: border-color var(--speed) var(--ease);
}

.field textarea {
    resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    border-color: var(--accent);
    outline: none;
}

.dropzone {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    padding: 18px;
    border: 1px dashed var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
    transition: border-color var(--speed) var(--ease);
}

.dropzone:hover {
    border-color: var(--accent);
}

.dropzone .icon {
    width: 22px;
    height: 22px;
    color: var(--accent);
}

.dropzone input {
    display: none;
}

.dropzone-title {
    font-size: 14px;
    font-weight: 600;
}

.dropzone-note {
    font-weight: 400;
    color: var(--muted);
}

.error-list {
    margin: 0;
    padding-left: 18px;
    color: var(--bad);
    font-weight: 600;
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
}

.list-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    font-variant-numeric: tabular-nums;
}

.list-table th,
.list-table td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    text-align: left;
    vertical-align: top;
}

.list-table th {
    position: sticky;
    top: 0;
    background: var(--surface);
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

.list-table tbody tr:last-child td {
    border-bottom: 0;
}

.list-table tbody tr:hover td {
    background: var(--surface-2);
}

.list-table .num {
    text-align: right;
}

.list-table a {
    color: var(--accent);
    font-weight: 600;
    text-decoration: none;
}

.list-table a:hover {
    text-decoration: underline;
}

.list-table tr.row-warn td {
    background: rgba(245, 196, 81, 0.08);
}

.list-table tr.row-warn td:first-child {
    box-shadow: inset 2px 0 0 var(--warn);
}

.person {
    display: flex;
    flex-direction: column;
    white-space: nowrap;
}

.sub-line {
    font-size: 12px;
    color: var(--muted);
}

.badge {
    display: inline-block;
    padding: 1px 8px;
    border: 1px solid var(--line);
    border-radius: var(--pill);
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge.good {
    color: var(--good);
    border-color: var(--good);
}

.badge.bad {
    color: var(--bad);
    border-color: var(--bad);
}

.badge.warn {
    color: var(--warn);
    border-color: var(--warn);
}

.empty {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 36px 12px;
    color: var(--muted);
}

.empty .icon {
    width: 32px;
    height: 32px;
}

.empty p {
    margin: 0;
}

.icon-btn {
    display: inline-flex;
    padding: 6px;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: color var(--speed) var(--ease);
}

.icon-btn:hover {
    color: var(--text);
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.modal[hidden] {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rbga(0, 0, 0, 0.6);
}

.modal-box {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 460px;
    max-height: calc(100vh - 32px);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
}

.modal-box.wide {
    max-width: 820px;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 12px 12px 18px;
    border-bottom: 1px solid var(--line);
}

.modal-body {
    padding: 16px 18px;
    overflow-y: auto;
}

.modal-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px;
    border-top: 1px solid var(--line);
}

body.modal-open {
    overflow: hidden;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    z-index: 50;
    display: none;
    max-width: calc(100vh - 32px);
    padding: 10px 16px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-weight: 600;
    transform: translateX(-50%);
}

.toast.show {
    display: block;
}

.toast.good {
    border-color: var(--good);
    color: var(--good);
}

.toast.bad {
    border-color: var(--bad);
    color: var(--bad);
}

.toast.busy {
    border-color: var(--warn);
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 10px;
    margin-bottom: 16px;
}

.inline-form .field {
    flex: 1 1 240px;
    max-width: 360px;
}

.list-table td.row-actions {
    text-align: right;
    white-space: nowrap;
}

.row-actions .icon-btn,
.row-actions .btn-quiet {
    vertical-align: middle;
}

.icon-btn:disabled {
    opacity: 0.3;
    cursor: default;
}

.list-table tr.row-muted td {
    color: var(--muted);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.form-errors:empty {
    display: none;
}

.form .panel-note {
    margin: 0;
}

.list-tools {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
}

.tool-input,
.status-select {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-size: 13px;
    transition: border-color var(--speed) var(--ease);
}

.tool-input:focus,
.status-select:focus,
.status-select:hover {
    border-color: var(--accent);
    outline: none;
}

.tool-input[type="search"] {
    width: 180px;
}

.list-count {
    font-size: 12px;
    color: var(--muted);
    white-space: nowrap;
}

.list-table td.ref {
    color: var(--muted);
    font-size: 12px;
    white-space: nowrap;
}

.long-text {
    display: block;
    min-width: 160px;
    max-width: 280px;
    white-space: pre-wrap;
    word-break: break-word;
}

.sub-line.late {
    color: var(--warn);
    font-weight: 600;
}

.status-select:disabled {
    opacity: 0.5;
}

@media (max-width: 700px) {
    .panel-head {
        flex-direction: column;
    }

    .tool-input[type="search"] {
        width: 100%;
    }
}

.photo-picker {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.photo-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.photo-list:empty {
    display: none;
}

.thumb {
    position: relative;
    width: 84px;
    height: 84px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    overflow: hidden;
    background: var(--surface-2);
}

.thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.thumb-remove {
    position: absolute;
    top: 4px;
    right: 4px;
    display: inline-flex;
    padding: 3px;
    border: 0;
    border-radius: var(--pill);
    background: rgba(0, 0, 0, 0.7);
    color: #fff;
    cursor: pointer;
}

.thumb-remove .icon {
    width: 12px;
    height: 12px;
}

.photo-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border: 1px solid var(--line);
    border-radius: var(--pill);
    background: var(--surface-2);
    color: var(--accent);
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
    cursor: pointer;
    transition: border-color var(--speed) var(--ease);
}

.photo-btn:hover {
    border-color: var(--accent);
}

.photo-btn .icon {
    width: 14px;
    height: 14px;
}

.photo-meta {
    margin-bottom: 14px;
}

.photo-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fill, minmax(220px, 1fr));
    gap: 14px;
}

.photo-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 0;
}

.photo-frame {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 220px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    background: var(--bg);
    overflow: hidden;
}

.photo-fram a {
    display: contents;
}

.photo-fram img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.photo-card figcaption {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.photo-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 12px;
    color: var(--muted);
}

a.btn-quiet {
    text-decoration: none;
}

.check-field {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    cursor: pointer;
}

.check-field input {
    width: 16px;
    height: 16px;
    accent-color: var(--accent);
}

.list-table tr.row-bad td {
    background: rgba(255, 107, 107, 0.07);
}

.list-table tr.row-bad td:first-child {
    box-shadow: inset 2px 0 0 var(--bad);
}

@media (max-width: 800px) {
    .app-header {
        flex-wrap: wrap;
        height: auto;
        gap: 0 12px;
        padding: 6px 16px 0;
    }

    .brand {
        padding: 8px 0;
    }

    .header-tools {
        order: 2;
    }

    .main-nav {
        order: 3;
        width: 100%;
        height: 42px;
        overflow-x: auto;
        scrollbar-width: none;
    }

    .main-nav::-webkit-scrollbar {
        display: none;
    }

    .nav-tab {
        flex: 0 0 auto;
        padding: 0 12px;
        white-space: nowrap;
    }

    .nav-tab.active::after {
        left: 12px;
        right: 12px;
    }

    .user-name {
        display: none;
    }

    .user-menu {
        padding-left: 0;
        border-left: 0;
    }

    .page {
        padding: 20px 16px 48px;
    }

    .sign-in {
        min-height: calc(100vh - 140px);
    }
}

.stat-grid {
    display: grid;
    grid-template-columns:
        repeat(auto-fit, minmax(210px, 1fr));
    gap: 14px;
}

.stat-tile {
    position: relative;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 16px 18px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    text-align: left;
    cursor: pointer;
    overflow: hidden;
    transition:
        border-color var(--speed) var(--ease),
        transform var(--speed) var(--ease);
}

.stat-tile::before {
    content: "";
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 3px;
    background: var(--line);
}

.stat-tile:hover {
    border-color: var(--muted);
    transform: translateY(-1px);
}

.stat-tile.good::before {
    background: var(--good);
}

.stat-tile.warn::before {
    background: var(--warn);
}

.stat-tile.bad::before {
    background: var(--bad);
}

.stat-top {
    display: flex;
    align-items: center;
    gap: 8px;
}

.stat-icon {
    display: inline-flex;
    padding: 6px;
    border-radius: var(--radius-sm);
    background: var(--surface-2);
    color: var(--accent);
}

.stat-icon .icon {
    width: 18px;
    height: 18px;
}

.stat-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.stat-value {
    font-size: 32px;
    font-weight: 700;
    line-height: 1.1;
    font-variant-numeric: tabular-nums;
}

.stat-tile.warn .stat-value {
    color: var(--warn);
}

.stat-tile.bad .stat-value {
    color: var(--bad);
}

.stat-note {
    font-size: 12px;
    color: var(--muted);
}

.stat-extra {
    align-self: flex-start;
    padding: 1px 8px;
    border: 1px solid var(--warn);
    border-radius: var(--pill);
    color: var(--warn);
    font-size: 12px;
    font-weight: 600;
}

.muted {
    color: var(--muted);
}

.pill-num {
    display: inline-block;
    min-width: 26px;
    padding: 1px 8px;
    border-radius: var(--pill);
    background: var(--surface-2);
    font-weight: 600;
    text-align: center;
}

.pill-num.warn {
    background: rgba(245, 196, 81, 0.15);
    color: var(--warn);
}

.pill-num.bad {
    background: rgba(255, 107, 107, 0.15);
    color: var(--bad);
}

.list-table tr.row-total td {
    border-top: 1px solid var(--line);
    font-weight: 700;
}

.panel-tools .icon {
    width: 14px;
    height: 14px;
}

.btn-danger {
    border-color: var(--bad);
    background: var(--bad);
    color: #1a0b0b;
}

.inline-form .field-role {
    flex: 0 0 120px;
}
