* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    background: #f4f6f9;
    color: #2c3e50;
    font-size: 14px;
    line-height: 1.5;
}

/* ---------- Login ---------- */
.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-card {
    background: #fff;
    padding: 36px 32px;
    border-radius: 10px;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.2);
    width: 380px;
}
.login-card h1 {
    margin: 0 0 24px;
    font-size: 22px;
    text-align: center;
    color: #2c3e50;
}
.login-card label {
    display: block;
    margin-bottom: 16px;
    font-size: 13px;
    color: #666;
}
.login-card input {
    display: block;
    width: 100%;
    margin-top: 6px;
    padding: 11px 13px;
    border: 1px solid #ddd;
    border-radius: 5px;
    font-size: 14px;
    transition: border-color 0.2s;
}
.login-card input:focus {
    outline: none;
    border-color: #4a69e2;
}
.login-card button {
    width: 100%;
    padding: 12px;
    margin-top: 8px;
    background: #4a69e2;
    color: #fff;
    border: 0;
    border-radius: 5px;
    font-size: 15px;
    cursor: pointer;
    transition: background 0.2s;
}
.login-card button:hover { background: #3a59d2; }
.login-card .error {
    padding: 10px 14px;
    background: #fde2e2;
    color: #c0392b;
    border-left: 3px solid #e74c3c;
    border-radius: 4px;
    margin-bottom: 16px;
    font-size: 13px;
}

/* ---------- Topbar ---------- */
.topbar {
    background: #fff;
    border-bottom: 1px solid #e5e9ee;
    padding: 0 28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 58px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.03);
}
.topbar h1 {
    font-size: 17px;
    margin: 0;
    color: #2c3e50;
    font-weight: 600;
}
.topbar nav a {
    display: inline-block;
    margin-left: 24px;
    color: #555;
    text-decoration: none;
    padding: 18px 0;
    border-bottom: 2px solid transparent;
    font-size: 14px;
    transition: color 0.2s, border-color 0.2s;
}
.topbar nav a:hover { color: #4a69e2; }
.topbar nav a.active {
    color: #4a69e2;
    border-bottom-color: #4a69e2;
    font-weight: 600;
}

/* ---------- Container ---------- */
.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 24px;
}

/* ---------- Stats ---------- */
.stats {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 20px;
}
.stat {
    background: #fff;
    padding: 20px 24px;
    border-radius: 8px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
    display: flex;
    flex-direction: column;
}
.stat .label {
    font-size: 12px;
    color: #888;
    margin-bottom: 8px;
}
.stat .value {
    font-size: 28px;
    font-weight: 600;
    color: #2c3e50;
}

/* ---------- Cards ---------- */
.card {
    background: #fff;
    border-radius: 8px;
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.card h2 {
    margin: 0 0 16px;
    font-size: 15px;
    color: #2c3e50;
    font-weight: 600;
}

/* ---------- Forms ---------- */
.form-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 14px;
    align-items: flex-end;
}
.form-inline label {
    display: flex;
    flex-direction: column;
    font-size: 12px;
    color: #666;
}
.form-inline input[type="text"],
.form-inline input[type="number"],
.form-inline input[type="password"],
.form-inline select {
    padding: 9px 12px;
    border: 1px solid #d0d7de;
    border-radius: 5px;
    font-size: 14px;
    min-width: 140px;
    margin-top: 5px;
    background: #fff;
}
.form-inline input:focus {
    outline: none;
    border-color: #4a69e2;
}
.form-inline button {
    padding: 9px 22px;
    background: #4a69e2;
    color: #fff;
    border: 0;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    transition: background 0.2s;
}
.form-inline button:hover { background: #3a59d2; }
.form-inline .btn-danger { background: #e74c3c; }
.form-inline .btn-danger:hover { background: #c0392b; }
.form-inline a {
    color: #888;
    font-size: 13px;
    text-decoration: none;
    padding: 11px 4px;
}
.form-inline a:hover { color: #4a69e2; }

/* ---------- Flash ---------- */
.flash {
    padding: 13px 18px;
    border-radius: 5px;
    margin-bottom: 16px;
    font-size: 14px;
}
.flash.success {
    background: #d9f3e4;
    color: #0e7c3d;
    border-left: 4px solid #2ecc71;
}
.flash.error {
    background: #fde2e2;
    color: #c0392b;
    border-left: 4px solid #e74c3c;
}

/* ---------- Generated keys ---------- */
.generated-keys {
    background: #fffbe6;
    border: 1px solid #ffe58f;
    padding: 18px;
    border-radius: 6px;
    margin-bottom: 20px;
}
.generated-keys h3 {
    margin: 0 0 10px;
    color: #ad6800;
    font-size: 14px;
}
.generated-keys textarea {
    width: 100%;
    height: 180px;
    font-family: Menlo, Consolas, "Courier New", monospace;
    font-size: 13px;
    padding: 12px;
    border: 1px solid #ffe58f;
    border-radius: 4px;
    resize: vertical;
    background: #fff;
    color: #2c3e50;
}
.generated-keys button {
    margin-top: 10px;
    padding: 7px 16px;
    background: #fa8c16;
    color: #fff;
    border: 0;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}
.generated-keys button:hover { background: #d46b08; }

/* ---------- Table ---------- */
.table-wrap { overflow-x: auto; }
.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 8px;
    font-size: 13px;
}
.data-table th,
.data-table td {
    padding: 11px 10px;
    text-align: left;
    border-bottom: 1px solid #eef1f4;
    vertical-align: middle;
    white-space: nowrap;
}
.data-table th {
    background: #f7f8fa;
    font-weight: 600;
    color: #555;
    font-size: 12px;
}
.data-table tbody tr:hover { background: #f8faff; }
.data-table code {
    font-family: Menlo, Consolas, "Courier New", monospace;
    font-size: 12px;
    color: #2c3e50;
    background: #f4f6f9;
    padding: 2px 6px;
    border-radius: 3px;
}
.data-table .col-key code {
    font-size: 13px;
    color: #1a4fbf;
    letter-spacing: 0.3px;
}
.data-table .muted { color: #bbb; }
.data-table .empty {
    text-align: center;
    padding: 40px;
    color: #aaa;
}
.data-table .actions { white-space: nowrap; }
.data-table .actions .inline {
    display: inline-block;
    margin-right: 4px;
}
.data-table .actions button {
    padding: 5px 12px;
    border: 1px solid #d0d7de;
    background: #fff;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: all 0.15s;
}
.data-table .actions button:hover {
    border-color: #4a69e2;
    color: #4a69e2;
}
.data-table .actions .btn-danger {
    border-color: #f5b7b1;
    color: #c0392b;
}
.data-table .actions .btn-danger:hover {
    background: #fde2e2;
    border-color: #e74c3c;
    color: #c0392b;
}

/* ---------- Status badges ---------- */
.badge-lic {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
}
.badge-lic.badge-unused  { background: #e3e8ee; color: #555; }
.badge-lic.badge-active  { background: #d9f3e4; color: #0e7c3d; }
.badge-lic.badge-expired { background: #fff4dc; color: #a56b0a; }
.badge-lic.badge-revoked { background: #fde2e2; color: #c0392b; }

/* ---------- Pager ---------- */
.pager {
    margin-top: 20px;
    text-align: center;
}
.pager a {
    display: inline-block;
    padding: 6px 12px;
    margin: 0 3px;
    border: 1px solid #d0d7de;
    background: #fff;
    color: #555;
    text-decoration: none;
    border-radius: 4px;
    font-size: 13px;
    transition: all 0.15s;
}
.pager a:hover { border-color: #4a69e2; color: #4a69e2; }
.pager a.active {
    background: #4a69e2;
    color: #fff;
    border-color: #4a69e2;
}

/* ---------- Danger zone ---------- */
.danger-zone {
    margin-top: 24px;
    padding: 18px;
    border: 1px dashed #e74c3c;
    border-radius: 6px;
    background: #fffafa;
}
.danger-zone h3 {
    color: #c0392b;
    margin: 0 0 8px;
    font-size: 14px;
}
.danger-zone p {
    margin: 0 0 12px;
    font-size: 13px;
    color: #888;
}
.danger-zone button {
    padding: 8px 18px;
    background: #e74c3c;
    color: #fff;
    border: 0;
    border-radius: 5px;
    cursor: pointer;
    font-size: 13px;
}
.danger-zone button:hover { background: #c0392b; }

/* ---------- Copy button ---------- */
.btn-copy {
    display: inline-block;
    padding: 4px 11px;
    margin-left: 6px;
    border: 1px solid #c5d3e8;
    background: #eef3ff;
    color: #3556c4;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    font-family: inherit;
    vertical-align: middle;
    transition: all 0.15s;
}
.btn-copy:hover {
    background: #4a69e2;
    color: #fff;
    border-color: #4a69e2;
}
.btn-copy.copied {
    background: #2ecc71 !important;
    color: #fff !important;
    border-color: #2ecc71 !important;
}
.generated-keys .btn-copy {
    margin-left: 0;
    margin-top: 10px;
    padding: 8px 18px;
    background: #fa8c16;
    color: #fff;
    border-color: #fa8c16;
    font-size: 13px;
}
.generated-keys .btn-copy:hover {
    background: #d46b08;
    border-color: #d46b08;
}

/* ---------- Clickable stat cards (filter shortcuts) ---------- */
.stat-link {
    text-decoration: none;
    color: inherit;
    transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
    border: 2px solid transparent;
}
.stat-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(74, 105, 226, 0.15);
}
.stat-link.stat-current {
    border-color: #4a69e2;
    background: #f4f7ff;
}

/* ---------- Filter tag ---------- */
.filter-tag {
    display: inline-block;
    padding: 2px 10px;
    margin-left: 6px;
    background: #eef3ff;
    color: #3556c4;
    border-radius: 10px;
    font-size: 11px;
    font-weight: 500;
    vertical-align: middle;
}

/* ---------- Login lock box ---------- */
.lock-box {
    line-height: 1.7;
}
.muted-small {
    display: inline-block;
    margin-top: 6px;
    font-size: 11px;
    color: #999;
    font-family: Menlo, Consolas, "Courier New", monospace;
}

/* ================================================== */
/*  Responsive — mobile & tablet                      */
/* ================================================== */
@media (max-width: 768px) {
    body { font-size: 13px; }

    /* Login */
    .login-card {
        width: auto;
        margin: 20px 16px;
        padding: 28px 22px;
        max-width: 420px;
    }
    .login-card h1 { font-size: 19px; }

    /* Topbar */
    .topbar {
        flex-direction: column;
        align-items: flex-start;
        height: auto;
        padding: 12px 16px;
    }
    .topbar h1 {
        font-size: 15px;
        margin-bottom: 4px;
    }
    .topbar nav {
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
    .topbar nav a {
        margin-left: 0;
        margin-right: 18px;
        padding: 8px 0;
        font-size: 13px;
    }

    /* Container */
    .container {
        padding: 14px 12px;
    }

    /* Stats — 2×2 */
    .stats {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-bottom: 14px;
    }
    .stat {
        padding: 14px 16px;
    }
    .stat .value {
        font-size: 22px;
    }
    .stat .label {
        font-size: 11px;
    }

    /* Cards */
    .card {
        padding: 16px 14px;
        margin-bottom: 14px;
    }
    .card h2 {
        font-size: 14px;
    }

    /* Forms stack vertically */
    .form-inline {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
    }
    .form-inline label {
        width: 100%;
    }
    .form-inline input[type="text"],
    .form-inline input[type="number"],
    .form-inline input[type="password"],
    .form-inline select {
        width: 100%;
        min-width: 0;
    }
    .form-inline button {
        width: 100%;
        padding: 12px 16px;
        font-size: 15px;
    }
    .form-inline a {
        padding: 8px 0;
        text-align: center;
        display: block;
    }

    /* Generated keys */
    .generated-keys {
        padding: 14px;
    }
    .generated-keys textarea {
        height: 220px;
        font-size: 12px;
    }
    .generated-keys .btn-copy {
        width: 100%;
    }

    /* Tables */
    .data-table {
        font-size: 12px;
    }
    .data-table th,
    .data-table td {
        padding: 8px 7px;
    }
    .data-table .col-key code {
        font-size: 12px;
    }
    .btn-copy {
        padding: 4px 9px;
        font-size: 11px;
        margin-left: 4px;
    }
    .data-table .actions {
        white-space: normal;
        min-width: 110px;
    }
    .data-table .actions .inline {
        display: inline-block;
        margin: 2px;
    }
    .data-table .actions button {
        padding: 5px 9px;
        font-size: 11px;
    }

    /* Pager */
    .pager a {
        padding: 5px 9px;
        font-size: 12px;
        margin: 0 2px;
    }

    /* Danger zone */
    .danger-zone {
        padding: 14px;
    }
    .danger-zone button {
        width: 100%;
    }

    /* Flash */
    .flash {
        padding: 11px 14px;
        font-size: 13px;
    }
}

@media (max-width: 480px) {
    .stats {
        grid-template-columns: 1fr;
    }
    .stat .value {
        font-size: 20px;
    }
    .topbar nav a {
        margin-right: 14px;
        font-size: 12px;
    }
}
