:root {
  color-scheme: light;
  --green-900: #07583f;
  --green-800: #076b4b;
  --green-700: #087f5b;
  --green-600: #099268;
  --green-100: #dff6ed;
  --green-50: #f0fbf7;
  --ink: #111827;
  --muted: #64748b;
  --line: #dfe7e4;
  --surface: #fff;
  --canvas: #f5f8f7;
  --danger: #c92a2a;
  --warning: #b7791f;
  --shadow: 0 12px 32px rgba(15, 50, 39, .08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; color: var(--ink); background: var(--canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
.hidden { display: none !important; }

.boot-screen, .login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(circle at 15% 15%, rgba(9,146,104,.16), transparent 30%),
    radial-gradient(circle at 85% 80%, rgba(19,187,133,.12), transparent 28%), #f8fbfa;
}
.boot-screen > div, .boot-screen > p { grid-area: 1/1; }
.boot-screen > p { margin-top: 104px; color: var(--muted); }
.brand-mark {
  width: 64px; height: 64px; display: grid; place-items: center; border-radius: 20px;
  background: linear-gradient(145deg, var(--green-600), var(--green-800)); color: white;
  font-size: 30px; font-weight: 800; box-shadow: 0 16px 32px rgba(8,127,91,.25);
}
.login-card { width: min(440px, 100%); padding: 38px; background: rgba(255,255,255,.94); border: 1px solid #e5ece9; border-radius: 28px; box-shadow: var(--shadow); }
.login-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 30px; }
.login-brand h1 { margin: 0; font-size: 25px; }
.login-brand p { margin: 3px 0 0; color: var(--muted); }
.login-card h2 { margin: 0 0 8px; font-size: 30px; }
.login-card > p { margin: 0 0 26px; color: var(--muted); line-height: 1.5; }

.field { display: grid; gap: 7px; margin-bottom: 17px; color: #334155; font-size: 14px; font-weight: 650; }
.field input, .field select, .search-input {
  width: 100%; min-height: 46px; border: 1px solid #d8e2de; border-radius: 12px; padding: 0 14px;
  color: var(--ink); background: #fbfdfc; outline: none; transition: border .15s, box-shadow .15s;
}
.field input:focus, .field select:focus, .search-input:focus { border-color: var(--green-600); box-shadow: 0 0 0 3px rgba(9,146,104,.12); }
.primary-button, .secondary-button, .danger-button, .icon-button, .text-button {
  min-height: 42px; border-radius: 11px; border: 1px solid transparent; padding: 0 15px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.primary-button { background: var(--green-700); color: white; box-shadow: 0 6px 14px rgba(8,127,91,.15); }
.primary-button:hover { background: var(--green-800); }
.secondary-button { color: var(--green-800); background: var(--green-50); border-color: #bee7d7; }
.danger-button { color: var(--danger); background: #fff5f5; border-color: #ffc9c9; }
.text-button { background: transparent; color: var(--green-800); padding-inline: 8px; }
.icon-button { width: 42px; padding: 0; color: #334155; background: #f3f6f5; border-color: #e2e9e6; }
.wide { width: 100%; }
.form-error { min-height: 20px; margin: 2px 0 10px; color: var(--danger); font-size: 14px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 248px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; background: #073f31; color: white; display: flex; flex-direction: column; }
.sidebar-brand { display: flex; align-items: center; gap: 11px; padding: 0 10px 26px; font-size: 21px; font-weight: 800; }
.sidebar-brand .brand-mark { width: 38px; height: 38px; border-radius: 12px; font-size: 18px; box-shadow: none; }
.nav { display: grid; gap: 7px; }
.nav-button { min-height: 46px; width: 100%; border: 0; border-radius: 12px; color: #d5ebe3; background: transparent; padding: 0 14px; display: flex; align-items: center; gap: 12px; font-weight: 650; text-align: left; }
.nav-button:hover, .nav-button.active { color: white; background: rgba(255,255,255,.12); }
.nav-icon { width: 24px; text-align: center; font-size: 19px; }
.sidebar-foot { margin-top: auto; padding: 15px 10px 0; border-top: 1px solid rgba(255,255,255,.14); }
.sidebar-foot strong, .sidebar-foot span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot span { margin-top: 4px; color: #b9d8cd; font-size: 13px; }

.main { min-width: 0; padding: 34px clamp(24px, 4vw, 58px) 54px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-head h1 { margin: 0; font-size: clamp(27px, 3vw, 36px); letter-spacing: -.02em; }
.page-head p { margin: 7px 0 0; color: var(--muted); }
.head-actions, .toolbar-actions, .inline-actions { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.connection-badge, .status-pill { display: inline-flex; align-items: center; gap: 7px; min-height: 31px; padding: 0 11px; border-radius: 999px; font-size: 13px; font-weight: 700; background: #eef2f1; color: #52625d; }
.connection-badge.connected, .status-pill.active, .status-pill.online { color: #08744f; background: #dff7ed; }
.status-pill.offline, .status-pill.revoked { color: #667085; background: #eef1f3; }
.status-pill.failed { color: var(--danger); background: #fff0f0; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

.stats-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card, .panel, .device-card, .share-card, .transfer-card { background: var(--surface); border: 1px solid #e3ebe8; border-radius: 18px; box-shadow: var(--shadow); }
.stat-card { padding: 20px; }
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { display: block; margin-top: 8px; font-size: 27px; }
.panel { padding: 22px; margin-bottom: 18px; }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 17px; }
.panel-title h2 { margin: 0; font-size: 19px; }
.panel-title p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }
.device-list, .share-list, .transfer-list { display: grid; gap: 14px; }
.device-card { padding: 20px; display: flex; align-items: center; gap: 16px; }
.device-glyph, .file-glyph { flex: 0 0 auto; width: 48px; height: 48px; border-radius: 14px; display: grid; place-items: center; background: var(--green-100); color: var(--green-800); font-size: 23px; }
.device-info { flex: 1; min-width: 0; }
.device-info h3 { margin: 0 0 5px; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.device-info p { margin: 0; color: var(--muted); font-size: 13px; }
.empty-state { padding: 46px 20px; text-align: center; color: var(--muted); }
.empty-state .empty-icon { display: grid; place-items: center; width: 58px; height: 58px; margin: 0 auto 15px; border-radius: 17px; background: var(--green-50); color: var(--green-700); font-size: 25px; }
.empty-state h3 { margin: 0 0 6px; color: var(--ink); }
.empty-state p { margin: 0 auto; max-width: 480px; line-height: 1.5; }

.file-toolbar { display: grid; grid-template-columns: minmax(180px, 1fr) auto; gap: 14px; margin-bottom: 16px; }
.breadcrumbs { display: flex; align-items: center; gap: 5px; flex-wrap: wrap; margin: 3px 0 17px; }
.crumb { border: 0; background: transparent; color: var(--green-800); padding: 4px 6px; border-radius: 7px; }
.crumb:last-child { color: var(--ink); font-weight: 700; }
.selection-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 14px; margin-bottom: 12px; background: var(--green-50); border: 1px solid #cdeade; border-radius: 12px; }
.file-table-wrap { overflow: auto; border: 1px solid #e2e9e6; border-radius: 14px; }
.file-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.file-table th { padding: 12px 14px; color: var(--muted); background: #f8faf9; font-size: 12px; text-align: left; text-transform: uppercase; letter-spacing: .04em; }
.file-table td { height: 68px; padding: 10px 14px; border-top: 1px solid #e9efed; vertical-align: middle; }
.file-table tr:hover td { background: #fbfdfc; }
.file-name { display: flex; align-items: center; gap: 12px; min-width: 0; }
.file-name button { padding: 0; border: 0; background: transparent; font-weight: 700; color: var(--ink); text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-glyph { width: 40px; height: 40px; border-radius: 11px; font-size: 18px; overflow: hidden; }
.file-glyph img { width: 100%; height: 100%; object-fit: cover; }
.row-actions { display: flex; gap: 5px; justify-content: flex-end; }
.row-actions button { min-height: 34px; border: 0; background: transparent; color: #475569; border-radius: 8px; padding: 0 8px; }
.row-actions button:hover { background: #edf3f0; }

.transfer-card { padding: 18px; }
.transfer-top { display: flex; align-items: flex-start; gap: 13px; }
.transfer-top .file-glyph { width: 44px; height: 44px; }
.transfer-copy { flex: 1; min-width: 0; }
.transfer-copy strong { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.transfer-copy span { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; }
.transfer-progress { width: 100%; height: 7px; margin: 15px 0 9px; overflow: hidden; border: 0; border-radius: 999px; background: #e8efec; appearance: none; }
.transfer-progress::-webkit-progress-bar { background: #e8efec; border-radius: 999px; }
.transfer-progress::-webkit-progress-value { background: linear-gradient(90deg, var(--green-600), #22b886); border-radius: 999px; }
.transfer-progress::-moz-progress-bar { background: linear-gradient(90deg, var(--green-600), #22b886); border-radius: 999px; }
.transfer-actions { margin-top: 13px; }
.transfer-meta { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }

.share-list { grid-template-columns: repeat(auto-fill, minmax(min(100%, 430px), 1fr)); align-items: stretch; }
.share-card { min-height: 465px; padding: 22px; display: flex; flex-direction: column; }
.share-head { display: flex; gap: 13px; align-items: flex-start; }
.share-title { flex: 1; min-width: 0; }
.share-title h3 { margin: 3px 0 7px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.share-title p { margin: 0; color: var(--muted); font-size: 13px; }
.share-separator { height: 1px; background: var(--line); margin: 18px 0; }
.copy-field { margin-bottom: 14px; }
.copy-field label { display: block; margin: 0 0 7px; color: #475569; font-size: 13px; font-weight: 650; }
.copy-row { display: grid; grid-template-columns: minmax(0,1fr) 44px; gap: 8px; }
.copy-value { min-height: 44px; display: flex; align-items: center; gap: 8px; padding: 0 13px; background: #f4f7f6; border-radius: 11px; color: #26323d; overflow: hidden; }
.copy-value span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.copy-value button { margin-left: auto; border: 0; background: transparent; font-size: 19px; color: #45566a; }
.share-access { display: flex; align-items: center; gap: 10px; color: #475569; font-size: 14px; }
.access-progress { width: 54px; height: 7px; border: 0; border-radius: 999px; background: #dce7e3; appearance: none; }
.access-progress::-webkit-progress-bar { background: #dce7e3; border-radius: 999px; }
.access-progress::-webkit-progress-value { background: var(--green-700); border-radius: 999px; }
.access-progress::-moz-progress-bar { background: var(--green-700); border-radius: 999px; }
.share-card .share-copy-all { margin-top: auto; }

.profile-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 17px; }
.avatar { width: 62px; height: 62px; border-radius: 50%; display: grid; place-items: center; color: white; background: linear-gradient(145deg, #31b985, var(--green-800)); font-size: 23px; font-weight: 800; }
.profile-details h2 { margin: 0 0 4px; }
.profile-details p { margin: 0; color: var(--muted); }
.detail-list { margin: 22px 0 0; border-top: 1px solid var(--line); }
.detail-row { display: grid; grid-template-columns: 150px 1fr; gap: 20px; padding: 15px 2px; border-bottom: 1px solid var(--line); }
.detail-row span:first-child { color: var(--muted); }

.modal { width: min(520px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 20px; box-shadow: 0 28px 80px rgba(0,0,0,.25); }
.modal::backdrop { background: rgba(13,31,25,.46); backdrop-filter: blur(3px); }
.modal-content { padding: 25px; }
.modal-action-grid { display: grid; gap: 9px; }
.spaced-top { margin-top: 18px; }
.modal-content h2 { margin: 0 0 7px; }
.modal-content > p { margin: 0 0 21px; color: var(--muted); line-height: 1.45; }
.modal-actions { display: flex; justify-content: flex-end; gap: 9px; margin-top: 23px; }
.check-row { display: flex; align-items: center; gap: 9px; margin: 14px 0; color: #334155; }
.toast-region { position: fixed; z-index: 100; right: 22px; bottom: 22px; display: grid; gap: 9px; }
.toast { max-width: 390px; padding: 13px 16px; color: white; background: #1d2d28; border-radius: 11px; box-shadow: var(--shadow); animation: toast-in .2s ease-out; }
.toast.error { background: #a61e1e; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (max-width: 820px) {
  .app-shell { display: block; padding-bottom: 72px; }
  .sidebar { position: fixed; z-index: 20; top: auto; bottom: 0; width: 100%; height: 68px; padding: 7px 10px max(7px, env(safe-area-inset-bottom)); flex-direction: row; background: rgba(7,63,49,.97); backdrop-filter: blur(12px); }
  .sidebar-brand, .sidebar-foot { display: none; }
  .nav { width: 100%; display: grid; grid-template-columns: repeat(5, 1fr); gap: 2px; }
  .nav-button { min-height: 54px; padding: 5px 2px; flex-direction: column; justify-content: center; gap: 2px; font-size: 10px; }
  .nav-icon { font-size: 18px; line-height: 20px; }
  .main { padding: 24px 18px 34px; }
  .page-head { align-items: flex-start; margin-bottom: 20px; }
  .stats-grid { grid-template-columns: 1fr; }
  .file-toolbar { grid-template-columns: 1fr; }
  .head-actions { justify-content: flex-end; }
  .device-card { align-items: flex-start; flex-wrap: wrap; }
  .device-card .inline-actions { width: 100%; }
  .device-card .inline-actions > button { flex: 1; }
  .share-list { grid-template-columns: 1fr; }
  .share-card { min-height: 440px; }
}

@media (max-width: 520px) {
  .login-card { padding: 27px 22px; border-radius: 22px; }
  .page-head { display: block; }
  .page-head .head-actions { margin-top: 13px; justify-content: flex-start; }
  .panel { padding: 16px; }
  .profile-card { grid-template-columns: auto 1fr; }
  .profile-card > button { grid-column: 1 / -1; }
  .detail-row { grid-template-columns: 1fr; gap: 5px; }
  .selection-bar { align-items: flex-start; flex-direction: column; }
  .share-card { padding: 18px; }
}
