:root {
    --bg: #090d17;
    --panel: rgba(24, 31, 52, .72);
    --panel-strong: rgba(32, 41, 67, .9);
    --line: rgba(255, 255, 255, .11);
    --text: #f7f9ff;
    --muted: #aeb8cc;
    --green: #25d366;
    --green-deep: #075e54;
    --red: #ff6a72;
    --yellow: #f6d65b;
    --shadow: 0 24px 70px rgba(0, 0, 0, .42);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    min-height: 100vh;
    color: var(--text);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background:
        radial-gradient(circle at 18% 20%, rgba(37, 211, 102, .16), transparent 26%),
        radial-gradient(circle at 82% 14%, rgba(108, 92, 231, .20), transparent 25%),
        linear-gradient(145deg, #05070d, #121727 55%, #070a12);
}

a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.tablet-frame {
    width: min(1540px, calc(100vw - 32px));
    height: min(996px, calc(100vh - 32px));
    margin: 16px auto;
    padding: 38px;
    border: 2px solid rgba(255,255,255,.45);
    border-radius: 54px;
    background: linear-gradient(135deg, #020306, #141722);
    box-shadow: var(--shadow), inset 0 0 0 9px #05060a;
    perspective: 1700px;
}

.app-shell {
    position: relative;
    display: grid;
    grid-template-columns: 112px 1fr;
    grid-template-rows: 1fr 70px;
    height: 100%;
    overflow: hidden;
    border-radius: 20px;
    background:
        linear-gradient(115deg, rgba(255,255,255,.08), transparent 40%),
        rgba(10, 15, 29, .88);
    transform: rotateX(1deg);
    box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.app-shell.compact { grid-template-rows: 1fr; }

.sidebar {
    grid-row: 1 / 3;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 34px 12px 22px;
    background: linear-gradient(180deg, rgba(37, 47, 76, .78), rgba(92, 49, 42, .42));
    border-right: 1px solid var(--line);
}

.side-logo, .nav-item, .logout-link {
    width: 86px;
    min-height: 74px;
    display: grid;
    place-items: center;
    gap: 5px;
    border-radius: 14px;
    color: var(--text);
    text-align: center;
    font-size: 22px;
}

.side-logo span, .nav-item span, .logout-link span { display: block; font-size: 12px; }
.sidebar nav { display: grid; gap: 8px; }
.nav-item { background: transparent; border: 1px solid transparent; }
.nav-item.active, .nav-item:hover {
    background: rgba(37, 211, 102, .18);
    border-color: rgba(37, 211, 102, .24);
    color: #9ff5bd;
    box-shadow: 0 16px 32px rgba(37, 211, 102, .12);
}
.logout-link { margin-top: auto; }

.workspace {
    min-width: 0;
    padding: 34px 30px 16px;
}

.topbar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 22px;
    margin-bottom: 24px;
}
.topbar h1 { margin: 0 0 2px; font-size: 24px; letter-spacing: 0; }
.topbar p, .topbar span { margin: 0; color: var(--muted); }
.clock-card { text-align: center; }
.clock-card strong { display: block; font-size: 38px; line-height: 1; }
.top-actions { display: flex; justify-content: flex-end; align-items: center; gap: 12px; }
.top-actions button, .chat-header button, .header-action, .composer-bar button, .round {
    width: 48px;
    height: 48px;
    border: 1px solid var(--line);
    border-radius: 18px;
    color: var(--text);
    background: rgba(255,255,255,.07);
    box-shadow: 0 10px 22px rgba(0,0,0,.18);
}

.profile-pill {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 9px 13px;
    min-width: 200px;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: rgba(255,255,255,.07);
}
.profile-pill span { display: block; color: #76ee9d; font-size: 12px; }
.avatar, .chat-avatar {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: linear-gradient(135deg, #e7f5ff, #5cc8ff 45%, #0b486b);
    color: #07111f;
    font-weight: 800;
}

.backup-strip {
    display: grid;
    grid-template-columns: repeat(5, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.backup-card {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    min-height: 142px;
    padding: 22px 20px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: linear-gradient(145deg, rgba(41,52,82,.92), rgba(20,28,50,.78));
    box-shadow: 0 16px 34px rgba(0,0,0,.28), inset 0 -20px 35px rgba(255,255,255,.04);
    transition: transform .2s ease, border-color .2s ease, box-shadow .2s ease;
}
.backup-card:hover { transform: translateY(-5px) rotateX(3deg); }
.backup-card.selected {
    border-color: rgba(37,211,102,.7);
    box-shadow: 0 0 34px rgba(37,211,102,.27), inset 0 -25px 36px rgba(37,211,102,.08);
}
.backup-day { font-size: 36px; font-weight: 900; line-height: 1; }
.backup-card span { display: block; color: var(--muted); font-size: 11px; }
.backup-card footer {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(4, auto 1fr);
    gap: 3px 8px;
    padding-top: 15px;
    border-top: 1px solid var(--line);
    font-size: 12px;
}
.status {
    align-self: start;
    padding: 9px 14px;
    border-radius: 14px;
    border: 1px solid rgba(37,211,102,.35);
    background: rgba(37,211,102,.16);
    font-size: 12px;
}
.status.partial { border-color: rgba(246,214,91,.35); background: rgba(246,214,91,.15); color: var(--yellow); }
.status.error { border-color: rgba(255,106,114,.35); background: rgba(255,106,114,.15); color: var(--red); }

.viewer-grid {
    display: grid;
    grid-template-columns: 330px minmax(420px, 1fr) 86px;
    gap: 18px;
    height: calc(100% - 242px);
    min-height: 470px;
}
.viewer-grid.full { height: calc(100% - 130px); grid-template-columns: 360px 1fr; }

.chat-list-panel, .message-panel, .timeline-panel, .shadow-controls, .settings-card {
    border: 1px solid var(--line);
    border-radius: 18px;
    background: var(--panel);
    box-shadow: 0 18px 42px rgba(0,0,0,.24);
    backdrop-filter: blur(18px);
}

.chat-list-panel { overflow: hidden; }
.search-box {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 16px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 20px;
    background: rgba(0,0,0,.15);
}
.search-box input {
    width: 100%;
    border: 0;
    outline: 0;
    color: var(--text);
    background: transparent;
}
.search-box button { border: 0; color: var(--muted); background: transparent; }
.chat-list { height: calc(100% - 78px); overflow: auto; }
.chat-row {
    width: 100%;
    display: grid;
    grid-template-columns: 54px 1fr auto;
    align-items: center;
    gap: 10px;
    padding: 12px 16px;
    border: 0;
    border-bottom: 1px solid rgba(255,255,255,.07);
    color: var(--text);
    background: transparent;
    text-align: left;
}
.chat-row.active, .chat-row:hover {
    background: linear-gradient(90deg, rgba(37,211,102,.28), rgba(37,211,102,.08));
}
.chat-copy { min-width: 0; }
.chat-copy strong, .chat-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-copy small, .chat-meta time { color: var(--muted); }
.chat-meta { display: grid; justify-items: end; gap: 5px; }
.chat-meta b {
    display: grid;
    place-items: center;
    min-width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--green);
    color: #052415;
    font-size: 12px;
}

.message-panel { display: grid; grid-template-rows: 66px 1fr 64px; overflow: hidden; }
.chat-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 18px;
    background: rgba(255,255,255,.06);
    border-bottom: 1px solid var(--line);
}
.chat-avatar.large { width: 46px; height: 46px; }
.chat-header small { display: block; color: var(--muted); }
.chat-header nav { margin-left: auto; display: flex; gap: 10px; }
.header-action {
    display: grid;
    place-items: center;
    width: auto;
    min-width: 48px;
    padding: 0 10px;
    font-size: 11px;
    font-weight: 800;
}
.messages-bg {
    position: relative;
    overflow: auto;
    padding: 44px 36px 20px;
    background:
        linear-gradient(rgba(5, 12, 22, .92), rgba(5, 12, 22, .92)),
        repeating-linear-gradient(45deg, transparent 0 24px, rgba(255,255,255,.04) 25px 26px);
}
.date-pill {
    position: absolute;
    top: 10px;
    left: 50%;
    transform: translateX(-50%);
    padding: 8px 16px;
    border-radius: 16px;
    background: rgba(255,255,255,.1);
    color: var(--muted);
    font-size: 12px;
}
.messages { display: grid; gap: 14px; }
.bubble-row { display: flex; }
.bubble-row.mine { justify-content: flex-end; }
.bubble {
    max-width: min(580px, 76%);
    padding: 12px 14px 8px;
    border-radius: 14px;
    color: #fff;
    background: #252c3d;
    box-shadow: 0 8px 20px rgba(0,0,0,.2);
}
.mine .bubble { background: linear-gradient(135deg, #075e54, #0b7d68); }
.bubble time {
    display: inline-block;
    margin-left: 12px;
    color: rgba(255,255,255,.72);
    font-size: 11px;
}
.image-placeholder {
    width: 260px;
    height: 146px;
    margin-top: 10px;
    overflow: hidden;
    border-radius: 12px;
    background: linear-gradient(135deg, #6cc9ff, #e8f6ff 55%, #1a6e70);
}
.image-placeholder div {
    width: 100%;
    height: 100%;
    background: radial-gradient(circle at 70% 22%, #fff59d 0 18px, transparent 20px), linear-gradient(145deg, transparent 55%, rgba(9,74,56,.75) 56%);
}
.image-placeholder span { display: none; }
.message-media {
    display: block;
    width: min(320px, 100%);
    max-height: 240px;
    object-fit: cover;
    margin-top: 10px;
    border-radius: 12px;
}
.message-audio {
    display: block;
    width: min(320px, 100%);
    margin-top: 10px;
}
.doc-link {
    display: block;
    margin-top: 10px;
    padding: 10px 12px;
    border: 1px solid rgba(255,255,255,.16);
    border-radius: 12px;
    background: rgba(255,255,255,.08);
}
.composer-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 18px;
    border-top: 1px solid var(--line);
    background: rgba(255,255,255,.06);
}
.composer-bar input {
    flex: 1;
    height: 44px;
    padding: 0 16px;
    border: 1px solid var(--line);
    border-radius: 20px;
    color: var(--text);
    background: rgba(0,0,0,.16);
}
.composer-bar .mic-button { background: var(--green); color: #052415; }

.timeline-panel {
    display: grid;
    align-content: space-between;
    justify-items: center;
    padding: 16px 10px;
}
.timeline-dates { display: grid; gap: 10px; width: 100%; }
.timeline-dates button {
    display: grid;
    place-items: center;
    min-height: 66px;
    border: 1px solid transparent;
    border-radius: 14px;
    color: var(--muted);
    background: transparent;
}
.timeline-dates button.active, .timeline-dates button:hover {
    border-color: rgba(37,211,102,.55);
    color: #caffdc;
    background: rgba(37,211,102,.18);
}
.timeline-dates strong { font-size: 18px; color: var(--text); }
.timeline-dates span { font-size: 10px; line-height: 1.1; }

.storage-bar {
    grid-column: 2;
    display: grid;
    grid-template-columns: minmax(250px, 1.5fr) repeat(5, 1fr);
    align-items: center;
    gap: 0;
    margin: 0 16px 14px 0;
    padding: 12px 20px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: rgba(22,31,52,.82);
}
.storage-bar > div { min-width: 0; padding: 0 16px; border-left: 1px solid rgba(255,255,255,.08); }
.storage-bar > div:first-child { border-left: 0; }
.storage-bar strong, .storage-bar b { display: block; }
.storage-bar strong { font-size: 12px; color: var(--muted); }
.storage-meter { display: grid; gap: 6px; }
.storage-meter > span { justify-self: end; margin-top: -21px; }
.storage-meter div { height: 8px; border-radius: 999px; background: rgba(255,255,255,.12); overflow: hidden; }
.storage-meter i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #fff06a, #37d878); }
.ok { color: var(--green); }

.login-body {
    display: grid;
    place-items: center;
}
.login-shell {
    width: min(430px, calc(100vw - 32px));
}
.login-panel {
    padding: 36px;
    border: 1px solid var(--line);
    border-radius: 24px;
    background: rgba(18, 27, 47, .82);
    box-shadow: var(--shadow);
}
.brand-mark {
    width: 64px;
    height: 64px;
    display: grid;
    place-items: center;
    border-radius: 18px;
    background: rgba(37,211,102,.18);
    color: #91f8b4;
    font-weight: 900;
}
.login-form { display: grid; gap: 16px; margin-top: 26px; }
.login-form label { display: grid; gap: 8px; color: var(--muted); }
.login-form input, .shadow-controls input, .shadow-controls select {
    width: 100%;
    padding: 13px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    color: var(--text);
    background: rgba(0,0,0,.22);
}
.login-form button, .shadow-controls button {
    padding: 14px 18px;
    border: 0;
    border-radius: 14px;
    color: #062514;
    background: var(--green);
    font-weight: 800;
}
.alert {
    padding: 12px 14px;
    border-radius: 12px;
    background: rgba(255,106,114,.16);
    color: #ffc7cc;
}
.alert.success {
    background: rgba(37,211,102,.16);
    color: #bdf8d0;
}

.empty-state {
    display: grid;
    align-content: center;
    gap: 8px;
    min-height: 180px;
    padding: 22px;
    color: var(--muted);
    text-align: center;
}
.empty-state strong {
    color: var(--text);
    font-size: 16px;
}
.empty-state.wide {
    grid-column: 1 / -1;
    min-height: 142px;
    border: 1px dashed rgba(255,255,255,.18);
    border-radius: 16px;
    background: rgba(255,255,255,.04);
}
.message-empty {
    min-height: 320px;
}

.shadow-controls {
    display: grid;
    grid-template-columns: 1.3fr 1fr 1fr auto;
    gap: 14px;
    padding: 16px;
    margin-bottom: 18px;
}
.shadow-controls label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

.settings-page {
    width: min(900px, calc(100vw - 32px));
    margin: 40px auto;
}
.settings-card { padding: 24px; margin: 18px 0; }

.admin-page {
    width: min(1280px, calc(100vw - 32px));
    margin: 28px auto;
}
.admin-top {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: center;
    margin-bottom: 18px;
}
.admin-top h1 { margin: 0; }
.admin-top p { margin: 6px 0 0; color: var(--muted); }
.admin-top nav {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}
.admin-top a, .admin-form button, .admin-table button {
    display: inline-grid;
    place-items: center;
    min-height: 40px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--text);
    background: rgba(255,255,255,.08);
}
.admin-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(280px, 1fr));
    gap: 18px;
}
.admin-form {
    display: grid;
    gap: 12px;
}
.admin-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
}
.admin-form input, .admin-form select, .admin-table input {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    background: rgba(0,0,0,.22);
}
.admin-form button {
    border-color: rgba(37,211,102,.35);
    background: rgba(37,211,102,.18);
    color: #bdf8d0;
    font-weight: 800;
}
.check-row {
    display: inline-flex !important;
    align-items: center;
    gap: 8px !important;
}
.check-row input {
    width: auto !important;
}
.admin-table-wrap {
    overflow: auto;
}
.admin-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 920px;
}
.admin-table th, .admin-table td {
    padding: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    text-align: left;
    vertical-align: middle;
}
.admin-table th {
    color: var(--muted);
    font-size: 12px;
    text-transform: uppercase;
}
.admin-table code {
    display: block;
    max-width: 360px;
    overflow: auto;
    padding: 8px;
    border-radius: 8px;
    background: rgba(0,0,0,.25);
    color: #9ff5bd;
}

@media (max-width: 1100px) {
    .tablet-frame { width: 100vw; height: auto; min-height: 100vh; margin: 0; padding: 10px; border-radius: 0; }
    .app-shell { grid-template-columns: 78px 1fr; grid-template-rows: auto; border-radius: 14px; }
    .storage-bar { display: none; }
    .backup-strip { grid-template-columns: minmax(230px, 1fr); overflow: auto; }
    .viewer-grid, .viewer-grid.full { grid-template-columns: 1fr; height: auto; }
    .timeline-panel { display: none; }
    .topbar { grid-template-columns: 1fr; }
    .top-actions { justify-content: flex-start; flex-wrap: wrap; }
    .message-panel { min-height: 560px; }
    .shadow-controls { grid-template-columns: 1fr; }
    .admin-grid { grid-template-columns: 1fr; }
    .admin-top { align-items: flex-start; flex-direction: column; }
}
