:root {
    --bg: #eef2f6;
    --surface: #ffffff;
    --surface-soft: #f8fafc;
    --line: #d6dde6;
    --line-strong: #b9c3cf;
    --text: #18202a;
    --muted: #667485;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --danger-bg: #f8d7da;
    --soft-bg: #e6f9e6;
    --ok-bg: #b2f2bb;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 14px;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}
h1 { margin: 0 0 4px; font-size: 24px; line-height: 1.15; }
h2 { font-size: 18px; margin: 18px 0 10px; }
h3 { font-size: 15px; margin: 0 0 8px; }
p { margin: 4px 0; color: var(--muted); }

input, button, select, .button-link {
    height: 34px;
    min-height: 34px;
    padding: 6px 10px;
    margin: 0;
    border-radius: 5px;
    font: inherit;
    line-height: 1.2;
}
input, select {
    min-width: 170px;
    background: #fff;
    border: 1px solid var(--line-strong);
    color: var(--text);
}
input:focus, select:focus {
    outline: 2px solid rgba(37, 99, 235, 0.18);
    border-color: var(--primary);
}
button, select { cursor: pointer; }
button, .button-link {
    color: #243244;
    font-weight: 600;
    background: linear-gradient(#f8fafc, #dbe3ec);
    border: 1px solid #aeb9c7;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.85), 0 1px 2px rgba(15, 23, 42, 0.14);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    white-space: nowrap;
}
button:hover, .button-link:hover { background: linear-gradient(#ffffff, #d2dbe7); }
button:active, .button-link:active {
    transform: translateY(1px);
    box-shadow: inset 0 1px 2px rgba(0,0,0,0.2);
}
.green {
    color: #12351f;
    background: linear-gradient(#dcfce7, #a7f3d0);
    border-color: #7fc89a;
}
.danger-button {
    color: #fff;
    background: linear-gradient(#ef4444, #b91c1c);
    border-color: #991b1b;
}
.danger-button:hover {
    background: linear-gradient(#dc2626, #991b1b);
}

.page-header {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: flex-start;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.08);
}
.form-row {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    margin-bottom: 10px;
}
.autocomplete {
    position: relative;
}
.autocomplete input {
    width: 100%;
}
.suggestions {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 20;
    max-height: 220px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: 6px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.16);
}
.suggestions.is-hidden {
    display: none;
}
.suggestion-item {
    width: 100%;
    min-width: 0;
    height: auto;
    min-height: 32px;
    padding: 7px 10px;
    justify-content: flex-start;
    border: 0;
    border-radius: 0;
    background: #fff;
    box-shadow: none;
    color: var(--text);
    font-weight: 600;
    text-align: left;
}
.suggestion-item:hover,
.suggestion-item.is-active {
    background: #e7edf4;
}
.stack-form {
    display: grid;
    gap: 8px;
    max-width: 520px;
}
.stack-form label {
    display: grid;
    gap: 4px;
    font-weight: 600;
}
.stack-form input { width: 100%; }

.panel, .toolbar {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px;
    margin-bottom: 12px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}
.toolbar h2 { margin-top: 0; }
.account-toggle-row { margin: 0 0 10px; }
.account-panel.is-hidden { display: none; }
.account-panel h2 { margin-top: 0; }
.edit-panel { max-width: 680px; }
.muted { color: var(--muted); }
.ship-name { font-weight: 700; }

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 8px;
    margin: 0 0 12px;
}
.summary-item {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 10px 12px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}
.summary-item span {
    display: block;
    color: var(--muted);
    margin-bottom: 3px;
    font-size: 12px;
}
.summary-item strong { font-size: 24px; line-height: 1; }
.summary-item.danger { background: #fff1f2; border-color: #fecdd3; }
.summary-item.soft { background: #f0fdf4; border-color: #bbf7d0; }
.summary-item.ok { background: #dcfce7; border-color: #86efac; }

.table-scroll {
    width: 100%;
    max-height: 62vh;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 12px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
}
table {
    width: 100%;
    min-width: 760px;
    background: var(--surface);
    border-collapse: collapse;
}
th, td {
    border-bottom: 1px solid #c8d1dc;
    padding: 6px 8px;
    vertical-align: top;
}
th {
    background: #e7edf4;
    color: #334155;
    font-size: 12px;
    text-align: left;
    position: sticky;
    top: 0;
    z-index: 5;
    box-shadow: 0 2px 0 #b8c3cf;
}
tbody tr:nth-child(even):not(.row-danger):not(.row-soft):not(.row-ok) { background: #f8fafc; }
tr:hover td { box-shadow: inset 0 0 0 9999px rgba(37, 99, 235, 0.035); }
tr:last-child td { border-bottom: 0; }
td button {
    width: 100%;
    max-width: 128px;
    min-width: 108px;
    height: 30px;
    min-height: 30px;
    padding: 4px 8px;
}
table form { margin: 0; }
.row-danger { background-color: var(--danger-bg); }
.row-soft { background-color: var(--soft-bg); }
.row-ok { background-color: var(--ok-bg); }
.status-on {
    color: #166534;
    font-size: 12px;
}
.status-off {
    color: #991b1b;
    font-size: 12px;
}
.status-age {
    color: #475569;
    font-size: 12px;
    margin-top: 2px;
}

.login-box {
    background: var(--surface);
    padding: 18px;
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(15, 23, 42, 0.12);
    border: 1px solid var(--line);
    max-width: 340px;
    margin: 80px auto;
}
.login-box form { display: grid; gap: 8px; }
.login-box input, .login-box button { width: 100%; }

@media (max-width: 900px) {
    body { padding: 10px; }
    h1 { font-size: 22px; }
    h2 { font-size: 17px; }
    .summary-grid { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
    table { min-width: 720px; font-size: 13px; }
    input, button, select, .button-link { min-height: 38px; height: 38px; }
}

@media (max-width: 640px) {
    body { padding: 8px; }
    h1 { font-size: 20px; }
    h2 { font-size: 16px; }
    .page-header { display: block; }
    .summary-grid { grid-template-columns: 1fr 1fr; }
    .form-row { display: block; }
    input:not([type="hidden"]), select, button, .button-link {
        width: 100%;
        max-width: none;
        margin-bottom: 6px;
    }
    table { min-width: 680px; font-size: 12px; }
    td, th { padding: 5px 6px; }
    td button { width: 100%; max-width: none; min-width: 0; margin-bottom: 0; }
    .autocomplete {
        width: 100%;
        margin-bottom: 6px;
    }
    .panel, .toolbar { padding: 8px; }
    .login-box { margin: 40px auto; }
}
