:root {
  color-scheme: light;
  --bg: #f6f6f2;
  --surface: #ffffff;
  --surface-soft: #fafaf7;
  --border: #e7e6df;
  --border-strong: #d6d5cc;
  --text: #1b1b17;
  --muted: #6f6f67;
  --muted-strong: #4b4b44;
  --primary: #15803d;
  --primary-2: #166534;
  --primary-deep: #14532d;
  --primary-soft: #e9f4ec;
  --grey-soft: #f0f0ea;
  --danger: #b42318;
  --shadow-sm: 0 1px 2px rgba(27, 27, 23, .05);
  --shadow-lg: 0 28px 70px rgba(27, 27, 23, .16);
  --radius-md: 16px;
  --radius-lg: 26px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(900px 520px at 6% -12%, rgba(21, 128, 61, .08), transparent 62%),
    radial-gradient(820px 520px at 100% 0%, rgba(110, 108, 98, .09), transparent 58%),
    var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, p { margin: 0; }
h1 { font-size: 1.45rem; letter-spacing: -.02em; }
h2 { font-size: 1.05rem; letter-spacing: -.01em; }
a { color: var(--primary-deep); }

.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.icon { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon-sm { width: 15px; height: 15px; }

.muted { color: var(--muted); }
.small { font-size: .8rem; }
.strong { color: var(--text); font-weight: 700; }
.form-error { color: var(--danger); font-size: .84rem; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px; padding: 11px 16px;
  font: inherit; font-weight: 700; font-size: .9rem; cursor: pointer;
  text-decoration: none; transition: transform .12s ease, box-shadow .15s ease, background .15s ease, border-color .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible, .side-link:focus-visible, .icon-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
.btn-primary {
  color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2));
  box-shadow: 0 10px 22px rgba(21, 128, 61, .22);
}
.btn-primary:hover { box-shadow: 0 14px 28px rgba(21, 128, 61, .28); }
.btn-soft { background: var(--primary-soft); color: var(--primary-deep); border-color: #d7eadc; }
.btn-soft:hover { background: #dcefe1; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--muted-strong); }
.btn-ghost:hover { background: var(--surface-soft); }
.btn-small { padding: 8px 12px; font-size: .8rem; border-radius: 10px; }
.btn-block { width: 100%; }

/* Login */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.login-card {
  width: min(960px, 100%); min-height: 570px;
  display: grid; grid-template-columns: 1.03fr .97fr;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); overflow: hidden;
  animation: rise .35s ease both;
}
.login-aside {
  position: relative; display: flex; flex-direction: column; gap: 26px;
  padding: 44px; color: #fff; overflow: hidden;
  background: linear-gradient(155deg, #1b1b17 0%, #2b2b26 46%, #14532d 100%);
}
.login-aside .brand { color: #fff; }
.login-aside-copy { margin-top: auto; display: grid; gap: 12px; max-width: 34ch; }
.login-aside-copy h2 { font-size: clamp(2rem, 3vw, 2.6rem); line-height: 1.08; letter-spacing: -.03em; }
.login-aside-copy p { color: rgba(255, 255, 255, .78); font-size: .96rem; }
.login-orb { position: absolute; border-radius: 50%; pointer-events: none; }
.login-orb-a { width: 240px; height: 240px; right: -90px; top: -80px; background: radial-gradient(circle, rgba(220, 252, 231, .26), transparent 70%); }
.login-orb-b { width: 320px; height: 320px; left: -140px; bottom: -160px; background: radial-gradient(circle, rgba(21, 128, 61, .5), transparent 70%); }
.login-panel { display: flex; flex-direction: column; justify-content: center; gap: 22px; padding: 48px 44px; }
.eyebrow { display: inline-flex; align-items: center; gap: 8px; font-size: .7rem; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; color: var(--primary); }
.login-panel-head h1 { margin-top: 8px; font-size: 1.95rem; }
.login-panel-head .muted { margin-top: 6px; }
.login-form { display: grid; gap: 16px; }
.login-hint { margin-top: 2px; text-align: center; font-size: .76rem; }

label { display: grid; gap: 7px; font-size: .84rem; font-weight: 700; color: var(--muted-strong); }
.input-wrap { position: relative; display: block; }
.input-wrap .icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: #9a9a90; }
.input-wrap input { padding-left: 42px; }
input, select {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: #fff; border: 1px solid var(--border-strong); border-radius: 12px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input::placeholder { color: #9a9a90; }
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px rgba(21, 128, 61, .13); }

.brand { font-weight: 800; letter-spacing: .22em; font-size: .92rem; color: var(--text); }
.brand-inverse { color: #fff; }

/* App shell */
.app-shell { display: grid; grid-template-columns: 264px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 28px;
  padding: 26px 20px; background: rgba(255, 255, 255, .9);
  backdrop-filter: blur(14px); border-right: 1px solid var(--border);
}
.side-nav { display: grid; gap: 5px; }
.side-link {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 11px 14px; border: 1px solid transparent; border-radius: 12px;
  background: transparent; color: var(--muted-strong); font: inherit; font-weight: 600;
  font-size: .9rem; cursor: pointer; text-align: left;
  transition: background .15s ease, color .15s ease, border-color .15s ease;
}
.side-link .icon { color: #a3a399; }
.side-link:hover { background: var(--surface-soft); color: var(--text); }
.side-link.active { background: var(--primary-soft); color: var(--primary-deep); border-color: #d7eadc; }
.side-link.active .icon { color: var(--primary); }
.side-foot { margin-top: auto; display: grid; gap: 12px; }
.side-user { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--surface-soft); border: 1px solid var(--border); }
.side-user-meta { display: grid; min-width: 0; }
.side-user-meta span:first-child { font-weight: 700; font-size: .86rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-role { font-size: .72rem; color: var(--muted); }
.side-logout { color: var(--muted); }

.avatar {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center;
  font-weight: 800; font-size: .95rem; color: #fff; flex: none;
  background: linear-gradient(135deg, var(--primary-2), var(--primary));
}
.avatar-lg { width: 64px; height: 64px; border-radius: 20px; font-size: 1.4rem; }

.main { width: 100%; max-width: 1240px; margin: 0 auto; padding: 34px clamp(20px, 4vw, 52px) 64px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head-copy h1 { font-size: clamp(1.5rem, 2.4vw, 1.9rem); }
.page-head-copy p { margin-top: 5px; }
.head-user { display: flex; align-items: center; gap: 12px; }
.head-user-meta { display: grid; text-align: right; }
.head-user-label { font-size: .72rem; color: var(--muted); }
.head-user-name { font-weight: 700; font-size: .9rem; }

.view { display: grid; gap: 18px; }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 16px; }
.stat {
  display: flex; align-items: center; gap: 14px; padding: 18px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-md); box-shadow: var(--shadow-sm);
  animation: rise .35s ease both;
}
.stat:nth-child(2) { animation-delay: .04s; }
.stat:nth-child(3) { animation-delay: .08s; }
.stat-icon { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; }
.stat-icon .icon { width: 21px; height: 21px; }
.stat-icon-green { background: var(--primary-soft); color: var(--primary); }
.stat-icon-grey { background: var(--grey-soft); color: var(--muted-strong); }
.stat-icon-deep { background: #e2ebe3; color: var(--primary-deep); }
.stat-copy { display: grid; }
.stat-value { font-size: 1.3rem; font-weight: 800; letter-spacing: -.02em; line-height: 1.2; }
.stat-label { font-size: .76rem; font-weight: 600; color: var(--muted); }

/* Cards and table */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); }
.table-card { overflow: hidden; animation: rise .35s ease both; animation-delay: .1s; }
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { margin: 0; }
.card-head .small { margin-top: 3px; }
.pill { display: inline-flex; align-items: center; padding: 5px 11px; border-radius: 999px; background: var(--surface-soft); border: 1px solid var(--border); color: var(--muted-strong); font-size: .74rem; font-weight: 700; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; min-width: 660px; }
th, td { text-align: left; padding: 14px 24px; vertical-align: middle; }
thead th { font-size: .68rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 800; background: var(--surface-soft); }
tbody tr { transition: background .12s ease; }
tbody tr:hover { background: #fbfbf7; }
tbody tr + tr { border-top: 1px solid var(--border); }
.th-actions { width: 1%; }
.cell-muted { color: var(--muted-strong); font-size: .88rem; }
.row-actions { display: flex; gap: 8px; justify-content: flex-end; white-space: nowrap; }

.file-cell { display: flex; align-items: center; gap: 13px; min-width: 0; }
.file-meta { display: grid; min-width: 0; }
.file-name { font-weight: 700; font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file-sub { font-size: .73rem; color: var(--muted); }
.file-tile { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; font-size: .6rem; font-weight: 800; letter-spacing: .04em; flex: none; }
.file-tile-text { background: var(--primary-soft); color: var(--primary-deep); }
.file-tile-data { background: var(--grey-soft); color: var(--muted-strong); }
.file-tile-image { background: #eaf1e4; color: #3f6212; }
.file-tile-secure { background: var(--primary-deep); color: #ecfdf5; }
.file-tile-default { background: var(--grey-soft); color: var(--muted-strong); }

.badge { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 999px; font-size: .71rem; font-weight: 700; }
.badge-owner { background: var(--primary); color: #fff; }
.badge-shared { background: var(--grey-soft); color: var(--muted-strong); }
.badge-shared::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--primary); }

.empty { display: grid; justify-items: center; gap: 10px; padding: 42px 20px; color: var(--muted); }
.empty-icon { width: 52px; height: 52px; border-radius: 16px; background: var(--surface-soft); border: 1px solid var(--border); display: grid; place-items: center; color: var(--muted); }
.empty-icon .icon { width: 22px; height: 22px; }

/* Forms */
.settings-form { display: grid; gap: 18px; max-width: 800px; }
.form-card { animation: rise .35s ease both; }
.card-body { padding: 22px 24px; display: grid; gap: 18px; }
.form-actions { display: flex; justify-content: flex-end; }

.switch-row { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 6px 0; cursor: pointer; font-weight: 400; }
.switch-copy { display: grid; gap: 2px; }
.switch-title { font-weight: 700; font-size: .9rem; color: var(--text); }
.switch-input { position: absolute; opacity: 0; width: 1px; height: 1px; pointer-events: none; }
.switch { position: relative; width: 46px; height: 27px; border-radius: 999px; background: #e3e3da; flex: none; transition: background .15s ease; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(27, 27, 23, .22); transition: transform .15s ease; }
.switch-input:checked + .switch { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.switch-input:checked + .switch::after { transform: translateX(19px); }
.switch-input:focus-visible + .switch { box-shadow: 0 0 0 4px rgba(21, 128, 61, .16); }

.profile-card { max-width: 800px; animation: rise .35s ease both; }
.profile-head { display: flex; align-items: center; gap: 16px; padding: 24px; border-bottom: 1px solid var(--border); }
.profile-head .muted { margin-top: 3px; }
.profile-form { display: grid; gap: 14px; padding: 24px; max-width: 440px; }

/* Modal */
.modal { border: none; padding: 0; background: transparent; width: min(480px, 92vw); border-radius: 20px; }
.modal::backdrop { background: rgba(27, 27, 23, .4); backdrop-filter: blur(4px); }
.modal-card { display: grid; gap: 16px; padding: 26px; background: var(--surface); border: 1px solid var(--border); border-radius: 20px; box-shadow: var(--shadow-lg); }
.modal-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; }
.modal-head .small { margin-top: 4px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 2px; }
.icon-btn { width: 36px; height: 36px; display: grid; place-items: center; flex: none; border-radius: 10px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; transition: background .15s ease, color .15s ease; }
.icon-btn:hover { background: var(--surface-soft); color: var(--text); }

/* Toast */
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 30; display: inline-flex; align-items: center; padding: 13px 17px; border-radius: 12px; background: #1b1b17; color: #fff; font-size: .86rem; box-shadow: var(--shadow-lg); max-width: min(420px, 90vw); animation: rise .25s ease both; }
.toast-error { background: var(--danger); }

/* Functional display preferences */
.table-card.is-compact th,
.table-card.is-compact td { padding-top: 9px; padding-bottom: 9px; }
.table-card.is-compact .file-sub { display: none; }
.table-card.hide-owner th:nth-child(2),
.table-card.hide-owner td:nth-child(2) { display: none; }
.table-card.hide-size th:nth-child(3),
.table-card.hide-size td:nth-child(3) { display: none; }

@keyframes rise {
  from { opacity: 0; transform: translateY(9px); }
  to { opacity: 1; transform: none; }
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 960px) {
  .app-shell { display: block; }
  .sidebar {
    position: sticky; top: 0; z-index: 20; height: auto;
    display: grid; grid-template-columns: 1fr auto; grid-template-areas: "brand logout" "nav nav";
    align-items: center; gap: 10px; padding: 12px 16px;
    background: rgba(255, 255, 255, .95); border-right: none; border-bottom: 1px solid var(--border);
  }
  .sidebar > .brand { grid-area: brand; }
  .side-nav { grid-area: nav; display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; width: 100%; }
  .side-link { justify-content: center; padding: 9px 8px; font-size: .78rem; gap: 8px; }
  .side-foot { grid-area: logout; margin: 0; display: block; }
  .side-user { display: none; }
  .side-logout { width: auto; padding: 8px 10px; }
  .side-logout span { display: none; }
  .main { padding: 22px 16px 48px; }
}

@media (max-width: 820px) {
  .login-card { grid-template-columns: 1fr; min-height: 0; max-width: 460px; }
  .login-aside { display: none; }
  .login-panel { padding: 38px 28px; }
}

@media (max-width: 620px) {
  .page-head { align-items: flex-start; }
  .head-user-meta { display: none; }
  .stats { grid-template-columns: 1fr; }
  .card-head { padding: 18px; }
  th, td { padding: 12px 16px; }
  .toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}
