/* ============================================================
   MT5 License Control – Professional Dark Theme
   ============================================================ */
:root {
    --bg:          #0f1117;
    --surface:     #1a1d27;
    --surface-2:   #222633;
    --border:      #2a2e3d;
    --text:        #e4e6ed;
    --text-dim:    #8b8fa3;
    --primary:     #6366f1;
    --primary-hover:#818cf8;
    --green:       #22c55e;
    --green-bg:    rgba(34,197,94,.12);
    --red:         #ef4444;
    --red-bg:      rgba(239,68,68,.12);
    --amber:       #f59e0b;
    --amber-bg:    rgba(245,158,11,.12);
    --radius:      8px;
    --sidebar-w:   240px;
}

* { margin:0; padding:0; box-sizing:border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    position: fixed; top:0; left:0; bottom:0;
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex; flex-direction: column;
    z-index: 100;
}
.sidebar-brand {
    display: flex; align-items: center; gap: 10px;
    padding: 24px 20px 20px;
    font-size: 17px; font-weight: 700;
    color: var(--primary);
}
.brand-icon { opacity: .9; }

.sidebar-nav {
    list-style: none;
    flex: 1;
    padding: 0 12px;
}
.sidebar-nav a {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 14px;
    border-radius: var(--radius);
    color: var(--text-dim);
    text-decoration: none;
    font-size: 14px;
    transition: all .15s;
    margin-bottom: 2px;
}
.sidebar-nav a:hover { background: var(--surface-2); color: var(--text); }
.sidebar-nav a.active { background: var(--primary); color: #fff; }

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}
.logout-btn {
    display: flex; align-items: center; gap: 8px;
    color: var(--text-dim); text-decoration: none;
    font-size: 13px; padding: 8px 10px; border-radius: var(--radius);
    transition: all .15s;
}
.logout-btn:hover { background: var(--red-bg); color: var(--red); }

/* ---- Main ---- */
main { padding: 32px 40px; }
main.with-sidebar { margin-left: var(--sidebar-w); }

/* ---- Page header ---- */
.page-header {
    display: flex; align-items: center; gap: 16px;
    margin-bottom: 28px;
    flex-wrap: wrap;
}
.page-header h1 { font-size: 24px; font-weight: 700; flex:1; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 9px 18px;
    border-radius: var(--radius);
    border: none;
    cursor: pointer;
    font-size: 14px; font-weight: 500;
    text-decoration: none;
    transition: all .15s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); }
.btn-secondary:hover { color: var(--text); border-color: var(--text-dim); }
.btn-full { width: 100%; justify-content: center; padding: 12px; font-size: 15px; }
.btn-sm { padding: 6px 12px; font-size: 13px; background: var(--surface-2); color: var(--text-dim); border: 1px solid var(--border); border-radius: 6px; }
.btn-sm:hover { color: var(--text); cursor: pointer; }

.btn-icon {
    display: inline-flex; align-items: center; justify-content: center;
    width: 32px; height: 32px;
    border-radius: 6px; border: none; background: transparent;
    color: var(--text-dim); text-decoration: none;
    transition: all .15s;
}
.btn-icon:hover { background: var(--surface-2); color: var(--text); }
.btn-icon.btn-warn:hover { background: var(--amber-bg); color: var(--amber); }
.btn-icon.btn-good:hover { background: var(--green-bg); color: var(--green); }
.btn-icon.btn-danger:hover { background: var(--red-bg); color: var(--red); }

/* ---- Stats ---- */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}
.stat-value { font-size: 32px; font-weight: 700; }
.stat-label { font-size: 13px; color: var(--text-dim); margin-top: 4px; }
.stat-active .stat-value { color: var(--green); }
.stat-expired .stat-value { color: var(--amber); }
.stat-revoked .stat-value { color: var(--red); }

/* ---- Table ---- */
.table-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.table-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
}
.table-header h2 { font-size: 16px; font-weight: 600; }
.search-input {
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 7px 14px;
    border-radius: 6px;
    font-size: 13px;
    width: 240px;
    outline: none;
    transition: border .15s;
}
.search-input:focus { border-color: var(--primary); }

.table-responsive { overflow-x: auto; }
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
thead th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-dim);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .04em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: rgba(99,102,241,.04); }

.user-cell { display: flex; flex-direction: column; }
.user-name { font-weight: 600; }
.user-email { font-size: 12px; color: var(--text-dim); }

.license-key {
    font-size: 12px;
    background: var(--surface-2);
    padding: 3px 8px;
    border-radius: 4px;
    cursor: pointer;
    word-break: break-all;
    border: 1px solid var(--border);
}
.license-key:hover { border-color: var(--primary); }

.last-check { font-size: 12px; color: var(--text-dim); }
.actions-cell { white-space: nowrap; }

.symbols-cell { max-width: 200px; }
.symbol-row { display: flex; align-items: center; gap: 6px; margin-bottom: 3px; }
.symbol-row:last-child { margin-bottom: 0; }
.symbol-label {
    font-size: 9px; font-weight: 700; text-transform: uppercase;
    padding: 1px 5px; border-radius: 3px; letter-spacing: .03em;
    flex-shrink: 0;
}
.symbol-allow { background: var(--green-bg); color: var(--green); }
.symbol-deny  { background: var(--red-bg);   color: var(--red); }
.symbol-list  { font-size: 12px; color: var(--text-dim); word-break: break-word; }
.text-dim { font-size: 12px; color: var(--text-dim); }

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
}
.badge-active  { background: var(--green-bg); color: var(--green); }
.badge-expired { background: var(--amber-bg); color: var(--amber); }
.badge-revoked { background: var(--red-bg);   color: var(--red);   }

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-dim);
}
.empty-state svg { margin-bottom: 12px; opacity: .4; }
.empty-state p  { margin-bottom: 16px; }

/* ---- Flash messages ---- */
.flash-container { margin-bottom: 20px; }
.flash {
    padding: 12px 18px;
    border-radius: var(--radius);
    font-size: 14px;
    margin-bottom: 8px;
}
.flash-success { background: var(--green-bg); color: var(--green); border: 1px solid rgba(34,197,94,.25); }
.flash-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid rgba(239,68,68,.25); }

/* ---- Forms ---- */
.form-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
    max-width: 760px;
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin-bottom: 20px;
}
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label {
    font-size: 13px; font-weight: 600; color: var(--text-dim);
}
.required { color: var(--red); }
.form-group input,
.form-group textarea,
.form-group select {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 9px 14px;
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border .15s;
    font-family: inherit;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--primary); }
.form-hint { font-size: 12px; color: var(--text-dim); }

.form-section { margin-bottom: 20px; }
.form-section-title {
    font-size: 14px; font-weight: 600; color: var(--text);
    margin-bottom: 14px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border);
}

.input-with-btn { display: flex; gap: 8px; }
.input-with-btn input { flex: 1; }

.readonly-field {
    background: var(--bg);
    padding: 9px 14px;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 13px;
}
.readonly-field code { word-break: break-all; }

.form-actions {
    display: flex; gap: 12px; justify-content: flex-end;
    margin-top: 24px;
    padding-top: 20px;
    border-top: 1px solid var(--border);
}

/* ---- Toggle ---- */
.toggle-label {
    display: flex; align-items: center; gap: 10px;
    cursor: pointer;
    font-size: 14px !important;
    font-weight: 500 !important;
    color: var(--text) !important;
}
.toggle-label input[type="checkbox"] { display: none; }
.toggle-switch {
    width: 42px; height: 24px;
    background: var(--border);
    border-radius: 12px;
    position: relative;
    transition: background .2s;
}
.toggle-switch::after {
    content: '';
    width: 18px; height: 18px;
    background: #fff;
    border-radius: 50%;
    position: absolute;
    top: 3px; left: 3px;
    transition: transform .2s;
}
.toggle-label input:checked + .toggle-switch { background: var(--green); }
.toggle-label input:checked + .toggle-switch::after { transform: translateX(18px); }

/* ---- Login ---- */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 400px;
}
.login-header {
    text-align: center;
    margin-bottom: 32px;
}
.login-icon { color: var(--primary); margin-bottom: 16px; }
.login-header h1 { font-size: 22px; font-weight: 700; }
.login-sub { color: var(--text-dim); font-size: 14px; margin-top: 4px; }
.login-card .form-group { margin-bottom: 18px; }

/* ---- Responsive ---- */
@media (max-width: 768px) {
    .sidebar { display: none; }
    main.with-sidebar { margin-left: 0; }
    main { padding: 20px 16px; }
    .form-grid { grid-template-columns: 1fr; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .search-input { width: 160px; }
}
