:root {
  --ink: #102d4e; --blue: #0754a0; --navy: #0b2d55; --muted: #647385;
  --line: #dce4eb; --soft: #f3f6fa; --pale: #eaf1f8; --white: #fff;
  --ok: #18794e; --warn: #b45309; --danger: #c0262d; --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink); background: var(--soft);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--soft); }
[hidden] { display: none !important; }
h1, h2, h3 { margin: 0 0 .4em; }
.muted { color: var(--muted); }
.error { color: var(--danger); min-height: 1.2em; margin: 0; }
input, textarea, select { font: inherit; color: inherit; border: 1px solid var(--line); border-radius: 10px; padding: .55em .7em; background: var(--white); width: 100%; }
input:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: -1px; border-color: transparent; }
textarea { resize: vertical; min-height: 2.6em; line-height: 1.4; }
label { display: grid; gap: .35em; font-weight: 600; font-size: .9rem; }

.btn { border: 1px solid var(--line); background: var(--white); color: var(--ink); border-radius: 10px; padding: .55em 1em; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; justify-content: center; gap: .4em; white-space: nowrap; }
.btn:hover { border-color: var(--blue); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--navy); }
.btn.danger { color: var(--danger); }
.btn.ghost { background: transparent; border-color: rgba(255,255,255,.25); color: #fff; }
.btn.small { padding: .3em .6em; font-size: .8rem; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; background: linear-gradient(135deg, var(--navy), var(--blue)); }
.login-card { background: var(--white); padding: 2rem; border-radius: 22px; width: min(400px, 100%); display: grid; gap: 1rem; box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.login-card h1 { margin: 0; font-size: 1.5rem; }
.login-card p.muted { margin: -.8rem 0 0; }
.login-logo { height: 48px; justify-self: start; }

/* layout */
.app { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: var(--navy); color: #fff; padding: 1.2rem .9rem; display: flex; flex-direction: column; gap: 1.2rem; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 800; font-size: 1.1rem; padding: 0 .4rem; }
.brand img { width: 30px; height: 30px; }
#nav { display: grid; gap: .25rem; }
#nav button { text-align: left; background: none; border: 0; color: #c9d7e8; padding: .65em .8em; border-radius: 10px; font: inherit; cursor: pointer; }
#nav button:hover { background: rgba(255,255,255,.08); color: #fff; }
#nav button.active { background: var(--blue); color: #fff; font-weight: 600; }
.sidebar-foot { margin-top: auto; display: grid; gap: .5rem; }
.main { padding: 1.5rem 2rem 6rem; min-width: 0; }

.toolbar { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; margin-bottom: 1rem; }
.toolbar .grow { flex: 1; min-width: 200px; }
.sticky-save { position: sticky; top: 0; z-index: 5; background: var(--soft); padding: .8rem 0; border-bottom: 1px solid var(--line); }
.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .15em .55em; border-radius: 99px; background: var(--pale); color: var(--blue); }
.badge.mod { background: #fff4e5; color: var(--warn); }
.badge.dirty { background: #fde8e8; color: var(--danger); }

.card { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.2rem; }
.groups { display: flex; gap: .4rem; flex-wrap: wrap; margin-bottom: 1rem; }
.groups button { border: 1px solid var(--line); background: var(--white); border-radius: 99px; padding: .35em .85em; font: inherit; font-size: .85rem; cursor: pointer; color: var(--ink); }
.groups button.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.entry { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); padding: .9rem 1rem; margin-bottom: .7rem; }
.entry.changed { border-color: #f5c27a; }
.entry-head { display: flex; gap: .5rem; align-items: center; margin-bottom: .5rem; flex-wrap: wrap; }
.entry-head code { font-size: .82rem; color: var(--muted); }
.entry-head .spacer { flex: 1; }
.langs { display: grid; grid-template-columns: repeat(3, 1fr); gap: .6rem; }
.langs label { font-size: .75rem; color: var(--muted); font-weight: 700; text-transform: uppercase; }
.hint { font-size: .8rem; color: var(--muted); margin: .3rem 0 0; }

.grid-media { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.media { background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; }
.media .thumb { aspect-ratio: 4/3; background: repeating-conic-gradient(#eef2f6 0 25%, #fff 0 50%) 0 0/16px 16px; display: grid; place-items: center; overflow: hidden; }
.media .thumb img, .media .thumb video { max-width: 100%; max-height: 100%; object-fit: contain; }
.media .thumb span { font-size: 2rem; }
.media .info { padding: .7rem .8rem; display: grid; gap: .5rem; }
.media .name { font-weight: 700; font-size: .88rem; word-break: break-all; }
.media .actions { display: flex; gap: .4rem; flex-wrap: wrap; }

.files { display: grid; grid-template-columns: 220px 1fr; gap: 1rem; }
.file-list { display: grid; gap: .3rem; align-content: start; }
.file-list button { text-align: left; border: 1px solid var(--line); background: var(--white); border-radius: 10px; padding: .5em .7em; font: inherit; font-size: .88rem; cursor: pointer; display: flex; justify-content: space-between; gap: .4rem; }
.file-list button.active { border-color: var(--blue); background: var(--pale); }
.code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; min-height: 70vh; white-space: pre; tab-size: 2; }

table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius); overflow: hidden; }
th, td { text-align: left; padding: .65rem .8rem; border-bottom: 1px solid var(--line); font-size: .9rem; }
th { background: var(--pale); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 150%); background: var(--ink); color: #fff; padding: .8em 1.3em; border-radius: 12px; transition: transform .25s; z-index: 50; max-width: calc(100% - 32px); }
.toast.show { transform: translate(-50%, 0); }
.toast.err { background: var(--danger); }

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  #nav { grid-template-columns: repeat(2, 1fr); }
  .main { padding: 1rem 16px 5rem; }
  .langs { grid-template-columns: 1fr; }
  .files { grid-template-columns: 1fr; }
}

/* interface language */
.login-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.lang-switch { display: inline-flex; border: 1px solid var(--line); border-radius: 10px; padding: 2px; gap: 2px; background: var(--white); }
.lang-switch button { border: 0; background: none; color: var(--muted); font: inherit; font-size: .8rem; font-weight: 700; padding: .35em .7em; border-radius: 8px; cursor: pointer; flex: 1; }
.lang-switch button[aria-pressed="true"] { background: var(--blue); color: #fff; }
.lang-switch.dark { display: flex; background: transparent; border-color: rgba(255,255,255,.25); }
.lang-switch.dark button { color: rgba(255,255,255,.75); }
.lang-switch.dark button[aria-pressed="true"] { background: #fff; color: var(--navy); }
