:root {
    --bg: #f7f7f4;
    --surface: #ffffff;
    --text: #37352f;
    --text-muted: #787774;
    --border: #e9e9e7;
    --border-strong: #d3d3d0;
    --accent: #2383e2;
    --accent-hover: #1a6ec7;
    --danger: #e03e3e;
    --danger-bg: #fdebec;
    --hover: rgba(55, 53, 47, 0.06);
    --shadow: 0 1px 2px rgba(15, 15, 15, 0.04), 0 4px 16px rgba(15, 15, 15, 0.04);
    --radius: 8px;
    --radius-sm: 6px;
}

* {
    box-sizing: border-box;
}

body {
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    margin: 0;
    -webkit-font-smoothing: antialiased;
}

.container {
    width: min(860px, calc(100% - 32px));
    margin: 48px auto 64px;
}

h2 {
    font-size: 1.75rem;
    font-weight: 600;
    letter-spacing: -0.02em;
    margin: 0 0 24px;
    color: var(--text);
}

hr {
    border: none;
    border-top: 1px solid var(--border);
    margin: 28px 0;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: color 0.15s ease;
}

a:hover {
    color: var(--accent-hover);
}

form {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

input {
    padding: 10px 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font: inherit;
    min-width: 160px;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder {
    color: var(--text-muted);
}

input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(35, 131, 226, 0.15);
}

input[type="number"] {
    -moz-appearance: textfield;
    appearance: textfield;
}

input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

button {
    padding: 10px 14px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    background: var(--text);
    color: #fff;
    font: inherit;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.05s ease;
}

button:hover {
    background: #2f2e2b;
}

button:active {
    transform: scale(0.98);
}

.search-form {
    margin-bottom: 20px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.search-form input {
    flex: 1;
    min-width: 220px;
}

.search-form a,
.nav-links a {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: var(--radius-sm);
    font-weight: 500;
}

.search-form a:hover,
.nav-links a:hover {
    background: var(--hover);
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
}

th {
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 12px 16px;
    background: #fafaf8;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--hover);
}

.delete-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    color: var(--danger);
    font-size: 0.875rem;
}

.delete-link:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

.edit-row-form {
    display: contents;
}

.table-input {
    width: 100%;
    min-width: 0;
    padding: 8px 10px;
    margin: 0;
}

.row-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
}

.save-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: var(--radius-sm);
    background: var(--accent);
    color: #fff;
    font-size: 0.875rem;
}

.save-btn:hover {
    background: var(--accent-hover);
}

.login-hint {
    color: var(--text-muted);
    margin: -12px 0 20px;
}

.error {
    color: var(--danger);
    background: var(--danger-bg);
    border: 1px solid #f5c2c7;
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    margin: 0 0 16px;
}

.empty {
    color: var(--text-muted);
    padding: 24px 16px;
    text-align: center;
    background: var(--surface);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}

.disclaimer {
    color: var(--text-muted);
    font-size: 0.875rem;
    line-height: 1.6;
    margin: -12px 0 20px;
}

.nav-links {
    display: flex;
    gap: 8px;
    margin-top: 24px;
}

.login-form {
    max-width: 360px;
    padding: 24px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.login-form input {
    width: 100%;
    min-width: 0;
}

.login-form button {
    width: 100%;
    margin-top: 4px;
}

.add-form {
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.add-form input {
    flex: 1;
    min-width: 140px;
}

.temporary-option {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 4px 0;
    color: var(--text);
    font-size: 0.9375rem;
    cursor: pointer;
}

.temporary-option input {
    width: auto;
    min-width: 0;
    margin: 0;
}

.temporary-duration {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
    color: var(--text);
    font-size: 0.9375rem;
}

.temporary-duration input {
    width: 100%;
    min-width: 0;
}

.temporary-edit-cell {
    min-width: 120px;
}

.temporary-edit-option {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 6px;
    font-size: 0.8125rem;
    white-space: nowrap;
}

.temporary-edit-option input {
    width: auto;
    min-width: 0;
    margin: 0;
}

.temporary-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #fff3bf;
    border: 1px solid #f0d060;
    color: #8a6d00;
    font-size: 0.75rem;
    font-weight: 600;
}

.temporary-badge--expired {
    background: #f1f1ef;
    border-color: var(--border-strong);
    color: var(--text-muted);
}

.new-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 3px 8px;
    border-radius: 999px;
    background: #dbeafe;
    border: 1px solid #2383e2;
    color: #1a6ec7;
    font-size: 0.75rem;
    font-weight: 600;
}

.row-temporary {
    background: #fffbeb;
}

.row-temporary:hover {
    background: #fff8dc;
}

.row-new {
    background: #eef6ff;
}

.row-new:hover {
    background: #dbeafe;
}

.mobile-client-card--temporary {
    background: #fffbeb;
    border-color: #f0d060;
}

.mobile-client-card--expired {
    opacity: 0.72;
    background: #f7f7f4;
}

.row-expired {
    background: #f7f7f4;
}

.row-expired:hover {
    background: #f1f1ef;
}

.admin-mobile {
    display: none;
}

.mobile-client-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 14px 16px;
}

.mobile-client-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.mobile-client-field:last-of-type {
    border-bottom: none;
}

.mobile-client-label {
    font-size: 0.6875rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.mobile-client-value {
    font-size: 1rem;
    word-break: break-word;
}

.mobile-client-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.edit-open-btn,
.mobile-delete-btn {
    flex: 1;
    min-height: 44px;
    border-radius: var(--radius-sm);
    font: inherit;
    font-weight: 500;
    text-align: center;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.edit-open-btn {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}

.mobile-delete-btn {
    border: 1px solid #f5c2c7;
    background: var(--danger-bg);
    color: var(--danger);
}

body.sheet-open {
    overflow: hidden;
}

.sheet-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    background: rgba(15, 15, 15, 0.45);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.25s ease, visibility 0.25s ease;
}

.sheet-overlay.is-open {
    opacity: 1;
    visibility: visible;
}

.sheet-panel {
    width: 100%;
    max-height: 92vh;
    overflow-y: auto;
    background: var(--surface);
    border-radius: 16px 16px 0 0;
    padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform 0.25s ease;
}

.sheet-overlay.is-open .sheet-panel {
    transform: translateY(0);
}

.sheet-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
}

.sheet-header h3 {
    margin: 0;
    font-size: 1.125rem;
}

.sheet-close {
    width: 44px;
    height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text-muted);
}

.sheet-form {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
}

.sheet-field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    width: 100%;
}

.sheet-field label {
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.sheet-field input {
    width: 100%;
    min-width: 0;
}

.sheet-submit,
.sheet-cancel {
    width: 100%;
    min-height: 44px;
}

.sheet-submit {
    background: var(--accent);
    margin-top: 4px;
}

.sheet-submit:hover {
    background: var(--accent-hover);
}

.sheet-cancel {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border-strong);
}

.sheet-cancel:hover {
    background: var(--hover);
}

@media (max-width: 768px) {
    .container {
        width: calc(100% - 24px);
        margin: 20px auto 40px;
        padding-bottom: env(safe-area-inset-bottom);
    }

    h2 {
        font-size: 1.375rem;
        margin-bottom: 16px;
    }

    hr {
        margin: 20px 0;
    }

    input,
    button,
    .table-input {
        font-size: 16px;
    }

    button,
    .save-btn,
    .delete-link {
        min-height: 44px;
        min-width: 44px;
    }

    .search-form,
    .add-form,
    .login-form {
        flex-direction: column;
        align-items: stretch;
        padding: 12px;
    }

    .add-form input,
    .add-form button {
        width: 100%;
        min-width: 0;
    }

    .temporary-option,
    .temporary-duration {
        min-height: 44px;
    }

    .temporary-duration input {
        width: 100%;
    }

    .search-form input,
    .search-form button,
    .add-form input,
    .add-form button,
    .login-form input,
    .login-form button {
        width: 100%;
        min-width: 0;
    }

    .search-form a {
        justify-content: center;
        text-align: center;
        min-height: 44px;
    }

    .login-form {
        max-width: none;
    }

    .disclaimer,
    .login-hint {
        margin: -8px 0 16px;
        font-size: 0.8125rem;
    }

    .nav-links {
        flex-direction: column;
        gap: 4px;
    }

    .nav-links a {
        justify-content: center;
        min-height: 44px;
    }

    .admin-desktop {
        display: none;
    }

    .admin-mobile {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .card:has(.data-table) {
        overflow: visible;
        background: transparent;
        border: none;
        box-shadow: none;
    }

    .data-table {
        display: block;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody {
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    .card:has(.data-table) .edit-row-form {
        display: block;
    }

    .card:has(.data-table) .data-table tr {
        display: block;
        background: var(--surface);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
        padding: 4px 14px 12px;
    }

    .card:has(.data-table) .data-table tr.row-temporary {
        background: #fffbeb;
        border-color: #f0d060;
    }

    .card:has(.data-table) .data-table tr.row-new {
        background: #eef6ff;
        border-color: #2383e2;
    }

    .card:has(.data-table) .data-table tbody tr:hover {
        background: var(--surface);
    }

    .card:has(.data-table) .data-table tbody tr.row-temporary:hover {
        background: #fff8dc;
    }

    .card:has(.data-table) .data-table tbody tr.row-new:hover {
        background: #dbeafe;
    }

    .card:has(.data-table) .data-table td {
        display: flex;
        flex-direction: column;
        align-items: stretch;
        gap: 6px;
        padding: 10px 0;
        border-bottom: 1px solid var(--border);
    }

    .card:has(.data-table) .data-table td:last-child {
        border-bottom: none;
    }

    .card:has(.data-table) .data-table td::before {
        content: attr(data-label);
        font-size: 0.6875rem;
        font-weight: 600;
        letter-spacing: 0.04em;
        text-transform: uppercase;
        color: var(--text-muted);
    }

    .card:has(.data-table) .data-table td.row-actions {
        flex-direction: row;
        justify-content: flex-end;
        gap: 8px;
        padding-top: 12px;
    }

    .card:has(.data-table) .data-table td.row-actions::before {
        display: none;
    }

    .card:has(.data-table) .save-btn {
        width: 44px;
    }
}
