/*
 * This is a manifest file that'll be compiled into application.css.
 *
 * With Propshaft, assets are served efficiently without preprocessing steps. You can still include
 * application-wide styles in this file, but keep in mind that CSS precedence will follow the standard
 * cascading order, meaning styles declared later in the document or manifest will override earlier ones,
 * depending on specificity.
 *
 * Consider organizing styles into separate files for maintainability.
 */

/* ========================================
   カラー変数定義
   ======================================== */
:root {
  --color-primary: #0080cb;
  --color-text-dark: rgb(41, 44, 53);
  --color-danger: rgb(167, 44, 9);
  --color-white: #fff;
  --color-bg-light: #f5f5f5;
  --color-border: #dee2e6;
  --color-bg-section: #f8f9fa;
}

/* ========================================
   リセットと基本設定
   ======================================== */

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  line-height: 1.6;
  color: var(--color-text-dark);
  background-color: var(--color-bg-light);
  padding: 20px;
  min-height: 100vh;
}

/* ========================================
   レイアウト
   ======================================== */

.container {
  max-width: 800px;
  margin: 0 auto;
  background-color: var(--color-white);
  padding: 40px;
  border-radius: 8px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

/* ========================================
   タイポグラフィ
   ======================================== */

h1 {
  font-size: 2rem;
  font-weight: 600;
  color: var(--color-text-dark);
  margin-bottom: 1.5rem;
  line-height: 1.3;
}

h2 {
  font-size: 1.5rem;
  font-weight: 600;
  color: var(--color-text-dark);
  margin-top: 2rem;
  margin-bottom: 1rem;
  line-height: 1.3;
}

p {
  margin-bottom: 1rem;
  line-height: 1.6;
}

small {
  font-size: 0.875rem;
  color: #666666;
  line-height: 1.5;
}

code {
  background-color: #f0f0f0;
  padding: 2px 6px;
  border-radius: 3px;
  font-family: "Monaco", "Courier New", monospace;
  font-size: 0.9em;
  color: var(--color-text-dark);
  word-break: break-all;
}

/* ========================================
   リンク
   ======================================== */

a {
  color: var(--color-primary);
  text-decoration: none;
  transition: color 0.2s ease;
}

a:hover {
  color: #006ba8;
  text-decoration: underline;
}

a:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ========================================
   ボタン
   ======================================== */

button,
input[type="submit"],
.btn {
  display: inline-block;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5;
  text-align: center;
  color: var(--color-white);
  background-color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  min-width: 120px;
}

button:hover,
input[type="submit"]:hover,
.btn:hover {
  background-color: #006ba8;
  border-color: #006ba8;
  color: var(--color-white);
  text-decoration: none;
}

button:focus,
input[type="submit"]:focus,
.btn:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

button:active,
input[type="submit"]:active,
.btn:active {
  background-color: #005685;
  border-color: #005685;
}

/* 削除ボタン */
button[data-confirm],
form[action*="delete"] button,
form[data-turbo-method="delete"] button {
  background-color: var(--color-danger);
  border-color: var(--color-danger);
}

button[data-confirm]:hover,
form[action*="delete"] button:hover,
form[data-turbo-method="delete"] button:hover {
  background-color: rgb(140, 37, 8);
  border-color: rgb(140, 37, 8);
}

/* セカンダリーボタン（リンク） */
.btn-secondary,
.actions a {
  display: inline-block;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 500;
  line-height: 1.5;
  text-align: center;
  color: var(--color-text-dark);
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  text-decoration: none;
  min-width: 120px;
}

.btn-secondary:hover,
.actions a:hover {
  background-color: var(--color-bg-section);
  border-color: #adb5bd;
  color: var(--color-text-dark);
  text-decoration: none;
}

.btn-secondary:focus,
.actions a:focus {
  outline: 2px solid var(--color-primary);
  outline-offset: 2px;
}

/* ボタングループ */
.actions {
  margin-top: 2rem;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.actions button,
.actions input[type="submit"],
.actions .btn,
.actions a {
  margin: 0;
}

/* ========================================
   フォーム
   ======================================== */

form {
  margin-top: 1.5rem;
}

.field {
  margin-bottom: 1.5rem;
}

label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  color: var(--color-text-dark);
  font-size: 0.95rem;
}

.field small {
  display: block;
  margin-top: 0.25rem;
  font-size: 0.875rem;
  color: #666666;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="url"],
textarea,
select {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  line-height: 1.5;
  color: var(--color-text-dark);
  background-color: var(--color-white);
  border: 1px solid #cccccc;
  border-radius: 4px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="url"]:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(0, 128, 203, 0.1);
}

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

/* ========================================
   エラーメッセージ
   ======================================== */

.error-messages {
  background-color: #fff3cd;
  border: 1px solid #ffc107;
  border-radius: 4px;
  padding: 16px;
  margin-bottom: 1.5rem;
}

.error-messages h2 {
  color: #856404;
  font-size: 1rem;
  font-weight: 600;
  margin-top: 0;
  margin-bottom: 0.75rem;
}

.error-messages ul {
  margin: 0;
  padding-left: 1.5rem;
  color: #856404;
}

.error-messages li {
  margin-bottom: 0.25rem;
}

/* ========================================
   フラッシュメッセージ
   ======================================== */

.flash-messages {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  max-width: 400px;
}

.flash {
  padding: 16px 20px;
  margin-bottom: 12px;
  border-radius: 6px;
  font-weight: 500;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
  animation: slideIn 0.3s ease;
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

.flash.notice,
.flash.success {
  background-color: #d4edda;
  color: #155724;
  border: 1px solid #c3e6cb;
}

.flash.alert,
.flash.error {
  background-color: #f8d7da;
  color: var(--color-danger);
  border: 1px solid #f5c6cb;
}

.flash.warning {
  background-color: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
}

/* ========================================
   ユーザー情報
   ======================================== */

.user-info {
  background-color: var(--color-bg-section);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 2rem;
}

.user-info p {
  margin-bottom: 0.5rem;
}

.user-info p:last-child {
  margin-bottom: 0;
}

.user-info strong {
  color: var(--color-primary);
  font-weight: 600;
}

/* ========================================
   SAML設定セクション
   ======================================== */

.saml-settings {
  margin-bottom: 2rem;
}

.saml-settings ul {
  list-style: none;
  padding: 0;
  margin-top: 1rem;
}

.saml-settings li {
  margin-bottom: 0.75rem;
}

.saml-settings a {
  display: inline-block;
  padding: 12px 20px;
  background-color: var(--color-bg-section);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  color: var(--color-text-dark);
  font-weight: 500;
  transition: all 0.2s ease;
  text-decoration: none;
}

.saml-settings a:hover {
  background-color: #e9ecef;
  border-color: #adb5bd;
  text-decoration: none;
}

/* ========================================
   IdP情報セクション
   ======================================== */

.idp-info-section {
  background-color: var(--color-bg-section);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 1.5rem;
}

.idp-info-section h2 {
  font-size: 1.25rem;
  margin-top: 0;
  margin-bottom: 0.75rem;
  color: var(--color-text-dark);
}

.code-with-copy {
  display: flex;
  gap: 12px;
  align-items: center;
  margin: 0.75rem 0;
}

.code-with-copy code {
  flex: 1;
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  padding: 12px;
  border-radius: 4px;
  font-size: 0.9rem;
  margin: 0;
}

.idp-info-section code {
  display: block;
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  padding: 12px;
  border-radius: 4px;
  margin: 0.75rem 0;
  font-size: 0.9rem;
}

.btn-copy {
  flex-shrink: 0;
  padding: 10px 16px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--color-white);
  background-color: var(--color-primary);
  border: 1px solid var(--color-primary);
  border-radius: 4px;
  cursor: pointer;
  transition: all 0.2s ease;
  min-width: auto;
  white-space: nowrap;
}

.btn-copy:hover {
  background-color: #006ba8;
  border-color: #006ba8;
}

.btn-copy:active {
  background-color: #005685;
  border-color: #005685;
}

.btn-copy-success {
  background-color: #28a745;
  border-color: #28a745;
}

.btn-copy-success:hover {
  background-color: #28a745;
  border-color: #28a745;
}

.idp-info-section details {
  margin-top: 1rem;
}

.idp-info-section summary {
  cursor: pointer;
  font-weight: 500;
  color: var(--color-primary);
  padding: 8px 0;
  user-select: none;
}

.idp-info-section summary:hover {
  text-decoration: underline;
}

.certificate-content {
  margin-top: 1rem;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.certificate-content textarea {
  width: 100%;
  min-height: 200px;
  padding: 12px;
  font-family: "Monaco", "Courier New", monospace;
  font-size: 0.85rem;
  line-height: 1.4;
  color: var(--color-text-dark);
  background-color: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  resize: vertical;
}

.certificate-content .btn-copy {
  align-self: flex-end;
}

/* ========================================
   テーブル
   ======================================== */

.table-container {
  overflow-x: auto;
  margin: 1.5rem 0;
  border-radius: 6px;
  border: 1px solid var(--color-border);
}

table {
  width: 100%;
  border-collapse: collapse;
  background-color: var(--color-white);
  margin: 0;
}

thead {
  background-color: var(--color-bg-section);
}

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  color: var(--color-text-dark);
  border-bottom: 2px solid var(--color-border);
  font-size: 0.95rem;
  white-space: normal;
  line-height: 1.4;
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
  max-width: 300px;
  word-break: break-all;
  overflow-wrap: break-word;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background-color: var(--color-bg-section);
}

td a {
  margin-right: 12px;
  font-weight: 500;
}

td button,
td form {
  display: inline-block;
  margin-right: 8px;
}

td button {
  padding: 6px 12px;
  font-size: 0.9rem;
  min-width: auto;
}

/* 操作列は幅を固定 */
td:last-child {
  white-space: nowrap;
  max-width: none;
  word-break: normal;
}

/* 戻るリンク（ボタンスタイルではない通常のリンク） */
.actions > a[href*="root"],
.actions > a[href*="back"],
.container > .actions:last-child > a:first-child {
  background-color: transparent;
  border: none;
  color: var(--color-primary);
  min-width: auto;
  padding: 0;
}

.actions > a[href*="root"]:hover,
.actions > a[href*="back"]:hover,
.container > .actions:last-child > a:first-child:hover {
  background-color: transparent;
  text-decoration: underline;
}

/* ========================================
   レスポンシブデザイン
   ======================================== */

@media (max-width: 768px) {
  body {
    padding: 10px;
  }

  .container {
    padding: 20px;
  }

  h1 {
    font-size: 1.5rem;
  }

  h2 {
    font-size: 1.25rem;
  }

  .flash-messages {
    left: 10px;
    right: 10px;
    max-width: none;
  }

  table {
    font-size: 0.875rem;
  }

  th,
  td {
    padding: 8px 10px;
  }

  td {
    max-width: 200px;
  }

  button,
  input[type="submit"],
  .btn {
    width: 100%;
  }

  .actions {
    flex-direction: column;
  }

  .actions button,
  .actions input[type="submit"],
  .actions .btn {
    width: 100%;
  }

  .code-with-copy {
    flex-direction: column;
    align-items: stretch;
  }

  .btn-copy {
    width: 100%;
  }
}

/* ========================================
   ユーティリティ
   ======================================== */

.text-center {
  text-align: center;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }
