:root {
    color-scheme: light;
    --bg: #f4f5f9;
    --surface: #ffffff;
    --border: #e4e7ee;
    --text: #1c2130;
    --text-muted: #6b7280;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --success: #16a34a;
    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .1);
    --shadow-lg: 0 12px 32px rgba(16, 24, 40, .18);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
}

button {
    font-family: inherit;
}

/* ---------- Auth screen ---------- */
.auth-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top, #eef0ff 0%, #f4f5f9 55%);
    padding: 20px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    padding: 36px 32px;
}

.auth-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 4px;
}

.auth-logo-icon {
    font-size: 28px;
}

.auth-logo h1 {
    font-size: 22px;
    margin: 0;
}

.auth-subtitle {
    color: var(--text-muted);
    font-size: 14px;
    margin: 0 0 24px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

/* ---------- Shared form fields ---------- */
.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
}

.field input[type="text"],
.field input[type="password"],
.field input[type="file"] {
    font-family: inherit;
    font-size: 14px;
    font-weight: 400;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fbfbfe;
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

.field input[type="text"]:focus,
.field input[type="password"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .15);
}

.field-hint {
    font-weight: 400;
    color: var(--text-muted);
    font-size: 12px;
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    margin: -8px 0 0;
}

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: none;
    border-radius: var(--radius-sm);
    padding: 10px 16px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background-color .15s, box-shadow .15s, opacity .15s;
    white-space: nowrap;
}

.btn:disabled {
    opacity: .6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--primary-hover);
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
    background: #f0f1f6;
}

.btn-danger {
    background: var(--danger);
    color: #fff;
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-hover);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    padding: 7px 9px;
    font-size: 14px;
}

.btn-sm {
    padding: 7px 10px;
    font-size: 13px;
}

.alert {
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 16px;
}

.alert-error {
    background: #fef2f2;
    color: #991b1b;
    border: 1px solid #fecaca;
}

/* ---------- App shell ---------- */
.app-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 28px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 700;
    font-size: 16px;
}

.brand-icon {
    font-size: 20px;
}

.logout-form {
    margin: 0;
}

.content {
    flex: 1;
    padding: 28px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

.content-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.content-header h1 {
    margin: 0 0 4px;
    font-size: 26px;
}

.content-subtitle {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

/* ---------- Table card ---------- */
.table-card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.table-scroll {
    overflow-x: auto;
}

.table-state {
    padding: 48px 24px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

.table-state button {
    margin-top: 14px;
}

.apk-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.apk-table th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--text-muted);
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.apk-table td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.apk-table tr:last-child td {
    border-bottom: none;
}

.apk-table tr:hover td {
    background: #fafaff;
}

.apk-name {
    font-weight: 600;
}

.apk-filename {
    color: var(--text-muted);
    font-size: 13px;
    word-break: break-all;
}

.col-actions {
    text-align: right;
}

.row-actions {
    display: flex;
    gap: 6px;
    justify-content: flex-end;
}

.link-copy {
    display: flex;
    align-items: center;
    gap: 6px;
}

.link-copy input {
    width: 150px;
    font-size: 12px;
    padding: 6px 8px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: #f8f9fc;
    color: var(--text-muted);
}

/* ---------- Modal ---------- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(17, 20, 30, .5);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 100;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    width: 100%;
    max-width: 440px;
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    animation: modal-in .15s ease-out;
}

@keyframes modal-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-small {
    max-width: 400px;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 0;
    font-size: 18px;
}

.modal-close {
    background: none;
    border: none;
    font-size: 16px;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    line-height: 1;
}

.modal-body {
    padding: 22px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 4px;
}

.upload-progress {
    height: 6px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.upload-progress-bar {
    height: 100%;
    width: 0%;
    background: var(--primary);
    transition: width .2s ease;
}

/* ---------- Toasts ---------- */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 200;
}

.toast {
    background: #1c2130;
    color: #fff;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    min-width: 220px;
    animation: toast-in .2s ease-out;
}

.toast-success {
    background: #15803d;
}

.toast-error {
    background: #b91c1c;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
    .content {
        padding: 18px;
    }

    .topbar {
        padding: 12px 18px;
    }

    .apk-table thead {
        display: none;
    }

    .apk-table, .apk-table tbody, .apk-table tr, .apk-table td {
        display: block;
        width: 100%;
    }

    .apk-table tr {
        border-bottom: 1px solid var(--border);
        padding: 12px 16px;
    }

    .apk-table td {
        border-bottom: none;
        padding: 6px 0;
        display: flex;
        justify-content: space-between;
        align-items: center;
        gap: 12px;
    }

    .apk-table td::before {
        content: attr(data-label);
        font-weight: 600;
        font-size: 12px;
        color: var(--text-muted);
        flex-shrink: 0;
    }

    .col-actions {
        text-align: left;
    }

    .row-actions {
        justify-content: flex-start;
    }

    .link-copy input {
        width: 110px;
    }
}
