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

body {
    font-family: var(--font-ui);
    color: var(--c-text);
}

img {
    max-width: 100%;
}

button,
input,
textarea,
select {
    font-family: inherit;
}

.btn {
    display: inline-block;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--c-primary-text);
    font-size: 14px;
    font-weight: 600;
    line-height: 1.4;
    text-align: center;
    cursor: pointer;
    transition: filter var(--ease-fast), background-color var(--ease-fast), border-color var(--ease-fast), color var(--ease-fast), transform var(--ease-fast);
}

.btn:hover:not(:disabled) {
    filter: brightness(0.92);
}

.btn:active:not(:disabled) {
    transform: scale(var(--press-scale));
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    filter: none;
    transform: none;
}

.btn-primary {
    background: var(--g-primary);
}

.btn-secondary {
    background: var(--g-secondary);
}

.btn-success {
    background: var(--g-success);
}

.btn-danger {
    background: var(--g-danger);
}

.btn-ghost {
    background: var(--c-surface);
    color: var(--c-text-dim);
    border: 2px solid var(--c-line);
}

.btn-ghost:hover:not(:disabled) {
    filter: none;
    border-color: var(--c-primary);
    color: var(--c-primary);
}

.btn-outline {
    background: var(--c-surface);
    color: var(--c-primary);
    border: 2px solid var(--c-primary);
}

.btn-outline:hover:not(:disabled) {
    filter: none;
    background: var(--c-primary);
    color: var(--c-primary-text);
}

.btn-soft {
    background: var(--c-primary-soft);
    color: var(--c-primary);
}

.btn-small {
    padding: 8px 15px;
    font-size: 13px;
}

.btn-large {
    padding: 14px 28px;
    font-size: 16px;
}

.btn-block {
    display: block;
    width: 100%;
    padding: 14px;
    font-size: 15px;
}

.btn-cta {
    display: block;
    width: 100%;
    padding: 16px;
    font-size: 18px;
    font-weight: bold;
    border-radius: var(--radius-sm);
    background: var(--g-primary);
    color: var(--c-primary-text);
}

.icon-btn {
    width: 40px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--c-surface-thumb);
    color: var(--c-tag-text);
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    transition: filter var(--ease-fast), transform var(--ease-fast);
}

.icon-btn:hover:not(:disabled) {
    filter: brightness(0.94);
}

.icon-btn:active:not(:disabled) {
    transform: scale(var(--press-scale));
}

.icon-btn.danger {
    background: var(--c-remove-bg);
    color: var(--c-remove-text);
}

.form-group {
    margin-bottom: 22px;
}

.form-label {
    display: block;
    color: var(--c-text-soft);
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 8px;
}

.form-label .optional {
    font-size: 13px;
    color: var(--c-text-mute);
    font-weight: 400;
}

.form-hint {
    font-size: 12px;
    color: var(--c-text-mute);
    font-weight: 400;
    margin-bottom: 10px;
}

.form-desc {
    color: var(--c-text-dim);
    font-size: 13px;
    margin-top: 6px;
    line-height: 1.6;
}

.form-input,
.form-textarea,
.form-select {
    width: 100%;
    padding: 12px 15px;
    border: 2px solid var(--c-line);
    border-radius: var(--radius-sm);
    background: var(--c-surface);
    font-size: 15px;
    transition: border-color var(--ease-fast);
    -webkit-user-select: text;
    -moz-user-select: text;
    user-select: text;
}

.form-input:focus,
.form-textarea:focus,
.form-select:focus {
    outline: none;
    border-color: var(--c-primary);
}

.form-input:disabled,
.form-textarea:disabled,
.form-select:disabled {
    background: var(--c-surface-muted);
    cursor: not-allowed;
}

.form-textarea {
    min-height: 100px;
    resize: vertical;
}

.form-select {
    cursor: pointer;
}

.input-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.input-suffix {
    color: var(--c-text-mid);
    font-weight: 600;
    font-size: 15px;
    white-space: nowrap;
}

.char-count {
    text-align: right;
    font-size: 12px;
    color: var(--c-text-mute);
    margin-top: 6px;
}

.hidden-file {
    display: none;
}

.switch-container {
    display: flex;
    align-items: center;
    gap: 15px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 56px;
    height: 32px;
    flex-shrink: 0;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    background: var(--c-line);
    border-radius: var(--radius-pill);
    transition: background 0.4s;
}

.slider:before {
    position: absolute;
    content: "";
    height: 24px;
    width: 24px;
    left: 4px;
    bottom: 4px;
    background: var(--c-surface);
    border-radius: 50%;
    transition: transform 0.4s;
}

.switch input:checked + .slider {
    background: var(--g-toggle-on);
}

.switch input:checked + .slider:before {
    transform: translateX(24px);
}

.switch-label {
    color: var(--c-text-mid);
    font-size: 14px;
}

.upload-zone {
    border: 2px dashed var(--c-line-dash);
    border-radius: var(--radius-md);
    padding: 22px;
    text-align: center;
    color: var(--c-text-mid);
    font-size: 14px;
    cursor: pointer;
    background: var(--c-surface);
    transition: border-color var(--ease-fast), color var(--ease-fast), background var(--ease-fast), transform var(--ease-fast);
}

.upload-zone:hover,
.upload-zone.dragging {
    border-color: var(--c-primary);
    color: var(--c-primary);
    background: var(--c-primary-soft);
}

.upload-zone:active {
    transform: scale(0.995);
}

.uploading-badge {
    display: inline-block;
    margin-top: 10px;
    font-size: 13px;
    color: var(--c-primary);
    font-weight: 600;
}

.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--c-scrim-strong);
    z-index: var(--z-modal);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.modal-overlay.open {
    display: flex;
}

.modal {
    background: var(--c-surface);
    border-radius: var(--radius-lg);
    padding: 28px;
    width: 100%;
    max-width: 400px;
    max-height: 86vh;
    overflow-y: auto;
    box-shadow: var(--shadow-xl);
}

.modal-sm {
    max-width: 340px;
}

.modal-lg {
    max-width: 520px;
}

.modal-xl {
    max-width: 560px;
}

.modal-flush {
    padding: 0;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    max-height: 82vh;
}

.modal h3 {
    margin-bottom: 16px;
    color: var(--c-text-soft);
    font-size: 18px;
}

.modal p {
    margin-bottom: 22px;
    color: var(--c-text-dim);
    line-height: 1.6;
    font-size: 14px;
}

.modal-actions {
    display: flex;
    gap: 10px;
    margin-top: 20px;
}

.modal-actions .btn {
    flex: 1;
    padding: 13px;
    font-size: 15px;
}

.modal-head {
    padding: 20px 22px;
    border-bottom: 1px solid var(--c-line-hair);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.modal-head h3 {
    margin-bottom: 0;
    font-size: 18px;
}

.modal-close {
    border: none;
    background: var(--c-surface-sunken);
    border-radius: var(--radius-sm);
    width: 34px;
    height: 34px;
    font-size: 17px;
    cursor: pointer;
    transition: transform var(--ease-fast), filter var(--ease-fast);
}

.modal-close:hover {
    filter: brightness(0.94);
}

.modal-close:active {
    transform: scale(var(--press-scale));
}

.modal-search {
    padding: 14px 22px;
    border-bottom: 1px solid var(--c-line-hair);
    flex-shrink: 0;
}

.modal-body {
    overflow-y: auto;
    padding: 12px 22px 22px;
}

.loading-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--c-scrim);
    z-index: var(--z-loading);
    justify-content: center;
    align-items: center;
}

.loading-overlay.open {
    display: flex;
}

.loading-content {
    background: var(--c-surface);
    padding: 40px 56px;
    border-radius: var(--radius-md);
    text-align: center;
    box-shadow: var(--shadow-xl);
}

.loading-spinner {
    border: 4px solid var(--c-line-soft);
    border-top: 4px solid var(--c-primary);
    border-radius: 50%;
    width: 50px;
    height: 50px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px;
}

.loading-text {
    font-size: 16px;
    font-weight: 500;
    color: var(--c-text);
}

.loading {
    text-align: center;
    padding: 60px 20px;
    color: var(--c-text-dim);
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--c-text-dim);
}

.empty-state h2 {
    font-size: 24px;
    margin-bottom: 12px;
}

.message-box {
    padding: 15px 20px;
    border-radius: var(--radius-sm);
    margin-bottom: 20px;
    display: none;
}

.message-box.open {
    display: block;
}

.message-box.success {
    background: var(--c-ok-bg);
    border: 2px solid var(--c-ok-line);
    color: var(--c-ok-text);
}

.message-box.error {
    background: var(--c-err-bg);
    border: 2px solid var(--c-err-line);
    color: var(--c-err-text);
}

.message-box.info {
    background: var(--c-info-bg);
    border: 2px solid var(--c-info-line);
    color: var(--c-info-text);
}

.badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
}

.badge-active {
    background: var(--c-ok-bg);
    color: var(--c-ok-text);
}

.badge-inactive {
    background: var(--c-surface-muted);
    color: var(--c-text-mute);
}

.badge-expired {
    background: var(--c-warn-bg);
    color: var(--c-warn-text);
}

.badge-exhausted {
    background: var(--c-err-bg);
    color: var(--c-err-text);
}

.badge-alert {
    background: var(--c-danger);
    color: var(--c-primary-text);
}

.chip {
    font-size: 12px;
    padding: 5px 10px;
    background: var(--c-chip-bg);
    border-radius: var(--radius-pill);
    color: var(--c-chip-text);
    word-break: break-all;
}

.chip.missing {
    background: var(--c-remove-bg);
    color: var(--c-err-text);
}

.chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.divider {
    height: 1px;
    background: var(--c-line);
    margin: 30px 0;
}

.viewer {
    display: none;
    position: fixed;
    inset: 0;
    background: var(--c-scrim-viewer);
    z-index: var(--z-viewer);
    justify-content: center;
    align-items: center;
    padding: 20px;
}

.viewer.open {
    display: flex;
}

.viewer img,
.viewer video {
    max-width: 100%;
    max-height: 100%;
    border-radius: var(--radius-sm);
}

.stars-display {
    color: var(--c-warn);
    letter-spacing: 2px;
}

.fallback-toast {
    position: fixed;
    left: 50%;
    bottom: 32px;
    transform: translate(-50%, 20px);
    max-width: min(420px, calc(100vw - 40px));
    padding: 13px 20px;
    border-radius: var(--radius-sm);
    background: var(--c-toast-bg);
    color: var(--c-toast-text);
    font-size: 14px;
    line-height: 1.5;
    text-align: center;
    box-shadow: var(--shadow-xl);
    opacity: 0;
    pointer-events: none;
    z-index: var(--z-loading);
    transition: opacity var(--ease-fast), transform var(--ease-fast);
}

.fallback-toast.open {
    opacity: 1;
    transform: translate(-50%, 0);
}

.fallback-toast[data-color="red"] {
    background: var(--c-err-text);
}

.fallback-toast[data-color="green"] {
    background: var(--c-ok-text);
}

.fallback-toast[data-place="top"] {
    top: 32px;
    bottom: auto;
    transform: translate(-50%, -20px);
}

.fallback-toast[data-place="top"].open {
    transform: translate(-50%, 0);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
