:root {
    --bg: #121212;
    --surface: #1c1c1c;
    --border: #3d3d3d;
    --text: #ebebeb;
    --muted: #9a9a9a;
    --accent: #c6c6c6;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, sans-serif;
}
a { color: var(--accent); text-decoration: none; }

.portal-topbar {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem;
    align-items: center;
    padding: 0.65rem 0.75rem;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
}
.portal-hamburger, .btn {
    min-width: 44px; min-height: 44px; border: 0; border-radius: 8px;
    background: var(--border); color: var(--text); padding: 0.55rem 0.9rem;
}
.portal-title { font-weight: 700; }
.portal-search { grid-column: 1 / -1; }
.portal-search input {
    width: 100%; min-height: 44px; border: 1px solid var(--border);
    border-radius: 8px; background: #101010; color: var(--text); padding: 0.45rem 0.6rem;
}
.portal-user { grid-column: 1 / -1; display: flex; justify-content: space-between; color: var(--muted); }

.portal-layout { display: grid; grid-template-columns: 1fr; min-height: calc(100vh - 130px); }
.portal-col { border-right: 1px solid var(--border); background: var(--surface); }
.portal-col-main { border-right: 0; background: var(--bg); }
.portal-col-title {
    padding: 0.75rem; font-size: 0.8rem; color: var(--muted); text-transform: uppercase;
    border-bottom: 1px solid var(--border);
}
.portal-item { display: block; min-height: 44px; padding: 0.65rem 0.75rem; color: var(--text); border-bottom: 1px solid rgba(255,255,255,0.04); }
.portal-item.active { border-left: 3px solid var(--accent); background: rgba(255,255,255,0.08); padding-left: calc(0.75rem - 3px); }
.portal-muted { color: var(--muted); padding: 0.75rem; }
.portal-actions { padding: 0.65rem 0.75rem 0.4rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.portal-row {
    display: grid; grid-template-columns: auto 1fr auto; gap: 0.6rem; align-items: center;
    margin: 0.35rem 0.5rem; padding: 0.55rem; border: 1px solid var(--border);
    border-radius: 10px; background: var(--surface); color: var(--text);
}
.portal-thumb {
    width: 58px; height: 58px; border-radius: 8px; object-fit: cover; border: 1px solid var(--border);
}
.portal-thumb-fallback {
    display: inline-flex; align-items: center; justify-content: center; background: #101010;
}
.portal-row-title { font-weight: 600; }
.portal-row-meta { font-size: 0.82rem; color: var(--muted); margin-top: 0.2rem; }
.portal-row-date { font-size: 0.76rem; color: var(--muted); white-space: nowrap; }

.portal-col-left, .portal-col-mid { display: none; }
.portal-layout.menu-open .portal-col-left, .portal-layout.menu-open .portal-col-mid { display: block; }

.flash { padding: 0.6rem 0.8rem; margin: 0.5rem; border-radius: 8px; border: 1px solid var(--border); }
.flash-err { color: #f2b7b7; border-color: #996a6a; }
.flash-ok { color: #cde0cd; border-color: #678267; }

.form-box {
    max-width: 400px; margin: 2rem auto; background: var(--surface); border: 1px solid var(--border);
    border-radius: 10px; padding: 1rem;
}
label { display: block; margin: 0.2rem 0; color: var(--muted); font-size: 0.9rem; }
input[type="text"], input[type="password"], input[type="date"], input[type="file"], select, textarea {
    width: 100%; min-height: 44px; border: 1px solid var(--border); border-radius: 8px;
    background: #101010; color: var(--text); padding: 0.45rem 0.6rem; margin-bottom: 0.6rem;
}
textarea { min-height: 96px; }

@media (min-width: 900px) {
    .portal-topbar { grid-template-columns: auto auto 1fr auto; }
    .portal-search, .portal-user { grid-column: auto; }
    .portal-layout { grid-template-columns: 220px 260px 1fr; min-height: calc(100vh - 72px); }
    .portal-col-left, .portal-col-mid { display: block; }
    .portal-hamburger { display: none; }
}

.wrap { max-width: 1100px; margin: 0 auto; }
.muted { color: var(--muted); font-size: 0.9rem; }

.form-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem 1.15rem;
    margin-bottom: 1rem;
}
.form-block h2 { margin: 0 0 0.75rem; font-size: 1.1rem; }
.form-block h3 { margin: 1rem 0 0.5rem; font-size: 1rem; }

.checkbox-row { display: flex; gap: 1rem; margin-bottom: 0.75rem; flex-wrap: wrap; }
.checkbox-row label { display: flex; align-items: center; gap: 0.35rem; color: var(--text); }

.pair-inline {
    display: grid;
    grid-template-columns: minmax(0, 9rem) minmax(0, 1fr);
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 0.75rem;
}
@media (max-width: 520px) { .pair-inline { grid-template-columns: 1fr; } }

.field-rows .pair {
    display: grid;
    grid-template-columns: 1fr 1fr auto;
    gap: 0.4rem;
    margin-bottom: 0.5rem;
    align-items: end;
}
@media (max-width: 600px) { .field-rows .pair { grid-template-columns: 1fr; } }
.field-rows input { margin-bottom: 0; }

button, .btn {
    cursor: pointer;
    font: inherit;
}
button[type="submit"], button:not([type]) {
    min-height: 44px;
    padding: 0.55rem 0.95rem;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: var(--bg);
    margin-right: 0.35rem;
    margin-bottom: 0.35rem;
}
button.secondary, .btn.secondary {
    background: var(--border);
    color: var(--text);
}
button.danger {
    background: rgba(201, 163, 163, 0.2);
    color: #e8d8d8;
}

.accordion-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin: 0.75rem 0;
    overflow: hidden;
}
.accordion-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    cursor: pointer;
}
.accordion-card-header-title { font-size: 0.95rem; font-weight: 500; }
.accordion-panel { padding: 0.75rem 0.85rem 0.9rem; }
.accordion-panel[hidden] { display: none; }

.detail-head {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 1rem;
}
.detail-head h1 { margin: 0; font-size: 1.35rem; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; }
.btn-head-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    color: var(--accent);
}
.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0;
}

body.modal-open { overflow: hidden; }
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 2000;
    align-items: center;
    justify-content: center;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
}
.modal.is-open { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.55); }
.modal-box {
    position: relative;
    z-index: 1;
    width: 100%;
    max-width: 400px;
    max-height: min(90vh, 520px);
    overflow: auto;
    padding: 1.1rem 1.2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.modal-form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }

textarea.letter-copy {
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.9rem;
    line-height: 1.4;
    min-height: 6.5rem;
    resize: vertical;
    width: 100%;
}

.kv-grid {
    display: grid;
    grid-template-columns: minmax(0, 9rem) minmax(0, 1fr);
    gap: 0.4rem 0.75rem;
    align-items: flex-start;
    margin: 0.35rem 0;
}
.kv-value-stack { display: grid; gap: 0.35rem; }
.codefield {
    display: block;
    padding: 0.25rem 0.4rem;
    border-radius: 6px;
    border: 1px dashed var(--border);
    background: rgba(0,0,0,0.25);
    font-family: ui-monospace, Consolas, monospace;
    font-size: 0.9rem;
    white-space: pre-wrap;
    word-break: break-word;
}

.notes-list { list-style: none; padding: 0; margin: 0; }
.notes-list li { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.notes-list time { font-size: 0.8rem; color: var(--muted); }

.files { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.thumb {
    width: 72px;
    height: 72px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--border);
}

.ticket-block {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.75rem;
    margin-bottom: 1rem;
    background: var(--surface);
}
.ticket-block h4 { margin: 0 0 0.5rem; }

.contact-export-wrap {
    display: flex;
    gap: 0.45rem;
    align-items: flex-start;
    margin: 0.35rem 0.5rem;
}
.contact-export-wrap .export-checkbox {
    width: auto;
    min-height: 44px;
    margin-top: 0.35rem;
    display: none;
    flex-shrink: 0;
}
.contact-export-link {
    flex: 1;
    min-width: 0;
    text-decoration: none;
    color: inherit;
}
.contact-export-body { min-width: 0; }

.btn.secondary.active {
    outline: 2px solid var(--accent);
}
